This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Perl_hv_fill() can return early if the hash only has 0 or 1 keys.
[perl5.git] / hv.c
diff --git a/hv.c b/hv.c
index 6476f51..916b64b 100644 (file)
--- a/hv.c
+++ b/hv.c
@@ -1844,6 +1844,11 @@ Perl_hv_fill(pTHX_ HV const *const hv)
 
     PERL_ARGS_ASSERT_HV_FILL;
 
+    /* No keys implies no buckets used.
+       One key can only possibly mean one bucket used.  */
+    if (HvTOTALKEYS(hv) < 2)
+        return HvTOTALKEYS(hv);
+
     if (ents) {
        HE *const *const last = ents + HvMAX(hv);
        count = last + 1 - ents;