develooper Front page | perl.perl5.porters | Postings from August 2001

[PATCH hv.c] newHVhv shouldn't reset xhv_max so often

Thread Next
From:
Abhijit Menon-Sen
Date:
August 2, 2001 18:08
Subject:
[PATCH hv.c] newHVhv shouldn't reset xhv_max so often
Message ID:
20010803063811.A19266@lustre.dyn.wiw.org
The appended patch teaches newHVhv not to reset xhv_max to 0 (from the
default of 7) when it's copying NULL or empty hashes.

Speaking of newHVhv (which is hardly worth optimising), I worked on a
patch to copy non-magical hashes fast (see the "#if 0" bit) when I was
trying to understand HEKs. Should I clean it up and submit it?

- ams

--- current/hv.c~	Fri Aug  3 05:52:31 2001
+++ current/hv.c	Fri Aug  3 06:21:57 2001
@@ -1180,16 +1180,16 @@
 HV *
 Perl_newHVhv(pTHX_ HV *ohv)
 {
-    register HV *hv;
-    STRLEN hv_max = ohv ? HvMAX(ohv) : 0;
-    STRLEN hv_fill = ohv ? HvFILL(ohv) : 0;
+    STRLEN hv_max, hv_fill;
+    register HV *hv = newHV();
 
-    hv = newHV();
+    if (!ohv || (hv_fill = HvFILL(ohv)) == 0)
+	return hv;
+
+    hv_max = HvMAX(ohv);
     while (hv_max && hv_max + 1 >= hv_fill * 2)
 	hv_max = hv_max / 2;	/* Is always 2^n-1 */
     HvMAX(hv) = hv_max;
-    if (!hv_fill)
-	return hv;
 
 #if 0
     if (! SvTIED_mg((SV*)ohv, PERL_MAGIC_tied)) {

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About