This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Perl_hv_fill(), count empty chains down, rather than used chains up.
authorNicholas Clark <nick@ccl4.org>
Sat, 13 Mar 2010 11:23:46 +0000 (11:23 +0000)
committerNicholas Clark <nick@ccl4.org>
Fri, 21 May 2010 17:56:25 +0000 (18:56 +0100)
The assumption is that most chains of a hash are in use.

Suggestion and initial patch by Ruslan Zakirov.

hv.c

diff --git a/hv.c b/hv.c
index 244feb6..1ff73b0 100644 (file)
--- a/hv.c
+++ b/hv.c
@@ -1880,12 +1880,13 @@ Perl_hv_fill(pTHX_ HV const *const hv)
     PERL_ARGS_ASSERT_HV_FILL;
 
     if (ents) {
-       HE *const *const end = ents + HvMAX(hv);
+       HE *const *const last = ents + HvMAX(hv);
+       count = last + 1 - ents;
 
        do {
-           if (*ents)
-               ++count;
-       } while (++ents <= end);
+           if (!*ents)
+               --count;
+       } while (++ents <= last);
     }
     return count;
 }