home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / lang / perl / 5709 < prev    next >
Encoding:
Internet Message Format  |  1992-09-03  |  1.7 KB

  1. Path: sparky!uunet!ogicse!uwm.edu!zaphod.mps.ohio-state.edu!usc!news!netlabs!lwall
  2. From: lwall@netlabs.com (Larry Wall)
  3. Newsgroups: comp.lang.perl
  4. Subject: Re: How fast is... (was Re: randomize.c)
  5. Message-ID: <1992Sep3.190504.12797@netlabs.com>
  6. Date: 3 Sep 92 19:05:04 GMT
  7. Article-I.D.: netlabs.1992Sep3.190504.12797
  8. References: <1992Aug31.183903.4143@cirrus.com> <1992Sep1.210332.26149@netlabs.com> <1992Sep2.135055.4659@Warren.MENTORG.COM>
  9. Sender: news@netlabs.com
  10. Organization: NetLabs, Inc.
  11. Lines: 26
  12. Nntp-Posting-Host: scalpel.netlabs.com
  13.  
  14. In article <1992Sep2.135055.4659@Warren.MENTORG.COM> tal@Warren.MENTORG.COM (Tom Limoncelli) writes:
  15. : In <1992Sep1.210332.26149@netlabs.com> lwall@netlabs.com (Larry Wall) writes:
  16. : >      ......                      Subscripting, however, happens
  17. : >constantly, so we optimize for that.
  18. : Are associative arrays optimized?  For example, many times I do:
  19. : if ( $foo{$thing} ne $frob ) {
  20. :     $foo{$thing} += $fratz;
  21. : }
  22. : Is there a one-entry cache or does it traverse the hash tables twice?
  23.  
  24. Well, traverse is perhaps a misleading word, since it usually lands
  25. right on the entry in question.  But it does calculate the hash value
  26. twice.  It doesn't know offhand that the value of $thing hasn't changed
  27. in the meanwhile.  It could be made to.  But you lose most of the
  28. advantage if you have to compare the two strings to find out.  The right
  29. way to do that is to associate the hash value with the string, and
  30. invalidate it if the string changes.  I'll need to redo how scalars
  31. are stored for Perl 5 anyway, so something like that might sneak in.
  32. Certainly an evaled string ought to cache its parse tree, and this is
  33. quite similar.
  34.  
  35. Larry
  36.