summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYves Orton <demerphq@gmail.com>2022-04-08 18:05:24 +0200
committerYves Orton <demerphq@gmail.com>2022-04-19 19:37:29 +0800
commitd4c01272cf568f8e4d3c4e19495db1e64827a8be (patch)
tree351948ba984cb1ffcda8410e5f57505099ac39f8
parent6241e4b3800e2717fea33ceb7b816b5dd83fc70d (diff)
downloadperl-d4c01272cf568f8e4d3c4e19495db1e64827a8be.tar.gz
hv.* - disable unshared keys except when requested
This disables the new unshared hash key logic by default. People who wish to try it out can enable it at build time with -DPERL_USE_UNSHARED_KEYS_IN_LARGE_HASHES in the configure process.
-rw-r--r--hv.c10
-rw-r--r--hv.h7
-rw-r--r--perl.c3
3 files changed, 18 insertions, 2 deletions
diff --git a/hv.c b/hv.c
index d4325bcd77..5e19941179 100644
--- a/hv.c
+++ b/hv.c
@@ -1576,7 +1576,12 @@ S_hv_delete_common(pTHX_ HV *hv, SV *keysv, const char *key, STRLEN klen,
This is a heuristic. There might be a better answer than 42, but for now
we'll use it.
+
+ NOTE: Configure with -Accflags='-DPERL_USE_UNSHARED_KEYS_IN_LARGE_HASHES'
+ to enable this new functionality.
*/
+
+#ifdef PERL_USE_UNSHARED_KEYS_IN_LARGE_HASHES
static bool
S_large_hash_heuristic(pTHX_ HV *hv, STRLEN size) {
if (size > 42
@@ -1588,6 +1593,7 @@ S_large_hash_heuristic(pTHX_ HV *hv, STRLEN size) {
}
return FALSE;
}
+#endif
STATIC void
S_hsplit(pTHX_ HV *hv, STRLEN const oldsize, STRLEN newsize)
@@ -1624,7 +1630,7 @@ S_hsplit(pTHX_ HV *hv, STRLEN const oldsize, STRLEN newsize)
return;
/* don't share keys in large simple hashes */
- if (S_large_hash_heuristic(aTHX_ hv, HvTOTALKEYS(hv)))
+ if (LARGE_HASH_HEURISTIC(hv, HvTOTALKEYS(hv)))
HvSHAREKEYS_off(hv);
@@ -1720,7 +1726,7 @@ Perl_hv_ksplit(pTHX_ HV *hv, IV newmax)
}
#endif
} else {
- if (S_large_hash_heuristic(aTHX_ hv, newmax))
+ if (LARGE_HASH_HEURISTIC(hv, newmax))
HvSHAREKEYS_off(hv);
Newxz(a, PERL_HV_ARRAY_ALLOC_BYTES(newsize), char);
xhv->xhv_max = newsize - 1;
diff --git a/hv.h b/hv.h
index bd81e5750c..2c5e796d9b 100644
--- a/hv.h
+++ b/hv.h
@@ -28,6 +28,13 @@
# define PERL_HASH_ITER_BUCKET(iter) (((iter)->xhv_riter) ^ ((iter)->xhv_rand))
#endif
+#ifdef PERL_USE_UNSHARED_KEYS_IN_LARGE_HASHES
+#define LARGE_HASH_HEURISTIC(hv,new_max) S_large_hash_heuristic(aTHX_ (hv), (new_max))
+#else
+#define LARGE_HASH_HEURISTIC(hv,new_max) 0
+#endif
+
+
/* entry in hash value chain */
struct he {
/* Keep hent_next first in this structure, because sv_free_arenas take
diff --git a/perl.c b/perl.c
index 486048aa68..057cd0e99a 100644
--- a/perl.c
+++ b/perl.c
@@ -1958,6 +1958,9 @@ S_Internals_V(pTHX_ CV *cv)
# ifdef PERL_USE_SAFE_PUTENV
" PERL_USE_SAFE_PUTENV"
# endif
+# ifdef PERL_USE_UNSHARED_KEYS_IN_LARGE_HASHES
+ " PERL_USE_UNSHARED_KEYS_IN_LARGE_HASHES"
+# endif
# ifdef SILENT_NO_TAINT_SUPPORT
" SILENT_NO_TAINT_SUPPORT"
# endif