diff options
author | Yves Orton <demerphq@gmail.com> | 2016-06-20 22:51:38 +0200 |
---|---|---|
committer | Yves Orton <demerphq@gmail.com> | 2016-06-22 18:21:32 +0200 |
commit | 8bf4c4010cc474d4000c2a8c78f6890fa5f1e577 (patch) | |
tree | b12d25aa70138f2dbc13bf1bb49a93fab7e7a4b7 /ext/Devel-Peek | |
parent | 6c50b67b99a3df9486896d14dc294825a148a673 (diff) | |
download | perl-8bf4c4010cc474d4000c2a8c78f6890fa5f1e577.tar.gz |
Change scalar(%hash) to be the same as 0+keys(%hash)
This subject has a long history see [perl #114576] for more discussion.
https://rt.perl.org/Public/Bug/Display.html?id=114576
There are a variety of reasons we want to change the return signature of
scalar(%hash). One is that it leaks implementation details about our
associative array structure. Another is that it requires us to keep track
of the used buckets in the hash, which we use for no other purpose but
for scalar(%hash). Another is that it is just odd. Almost nothing needs to
know these values. Perhaps debugging, but we have several much better
functions for introspecting the internals of a hash.
By changing the return signature we can remove all the logic related
to maintaining and updating xhv_fill_lazy. This should make hot code
paths a little faster, and maybe save some memory for traversed hashes.
In order to provide some form of backwards compatibility we adds three
new functions to the Hash::Util namespace: bucket_ratio(), num_buckets()
and used_buckets(). These functions are actually implemented in
universal.c, and thus always available even if Hash::Util is not loaded.
This simplifies testing. At the same time Hash::Util contains backwards
compatible code so that the new functions are available from it should
they be needed in older perls.
There are many tests in t/op/hash.t that are more or less obsolete after
this patch as they test that xhv_fill_lazy is correctly set in various
situations. However since we have a backwards compat layer we can just
switch them to use bucket_ratio(%hash) instead of scalar(%hash) and keep
the tests, just in case they are actually testing something not tested
elsewhere.
Diffstat (limited to 'ext/Devel-Peek')
-rw-r--r-- | ext/Devel-Peek/t/Peek.t | 34 |
1 files changed, 5 insertions, 29 deletions
diff --git a/ext/Devel-Peek/t/Peek.t b/ext/Devel-Peek/t/Peek.t index 56522af1e8..41898fea85 100644 --- a/ext/Devel-Peek/t/Peek.t +++ b/ext/Devel-Peek/t/Peek.t @@ -783,7 +783,7 @@ do_test('ENAME on a stash', AUX_FLAGS = 0 # $] > 5.019008 ARRAY = $ADDR KEYS = 0 - FILL = 0 \(cached = 0\) + FILL = 0 MAX = 7 RITER = -1 EITER = 0x0 @@ -806,7 +806,7 @@ do_test('ENAMEs on a stash', AUX_FLAGS = 0 # $] > 5.019008 ARRAY = $ADDR KEYS = 0 - FILL = 0 \(cached = 0\) + FILL = 0 MAX = 7 RITER = -1 EITER = 0x0 @@ -832,7 +832,7 @@ do_test('ENAMEs on a stash with no NAME', AUX_FLAGS = 0 # $] > 5.019008 ARRAY = $ADDR KEYS = 0 - FILL = 0 \(cached = 0\) + FILL = 0 MAX = 7 RITER = -1 EITER = 0x0 @@ -882,7 +882,7 @@ do_test('small hash after keys', ARRAY = $ADDR \\(0:[67],.*\\) hash quality = [0-9.]+% KEYS = 2 - FILL = [12] \\(cached = 0\\) + FILL = [12] MAX = 7 RITER = -1 EITER = 0x0 @@ -912,7 +912,7 @@ do_test('small hash after keys and scalar', ARRAY = $ADDR \\(0:[67],.*\\) hash quality = [0-9.]+% KEYS = 2 - FILL = ([12]) \\(cached = \1\\) + FILL = ([12]) MAX = 7 RITER = -1 EITER = 0x0 @@ -927,30 +927,6 @@ do_test('small hash after keys and scalar', COW_REFCNT = 1 ){2}'); -# This should immediately start with the FILL cached correctly. -my %large = (0..1999); -$b = %large; -do_test('large hash', - \%large, -'SV = $RV\\($ADDR\\) at $ADDR - REFCNT = 1 - FLAGS = \\(ROK\\) - RV = $ADDR - SV = PVHV\\($ADDR\\) at $ADDR - REFCNT = 2 - FLAGS = \\($PADMY,OOK,SHAREKEYS\\) - AUX_FLAGS = 0 # $] > 5.019008 - ARRAY = $ADDR \\(0:\d+,.*\\) - hash quality = \d+\\.\d+% - KEYS = 1000 - FILL = (\d+) \\(cached = \1\\) - MAX = 1023 - RITER = -1 - EITER = 0x0 - RAND = $ADDR - Elt .* -'); - # Dump with arrays, hashes, and operator return values @array = 1..3; do_test('Dump @array', '@array', <<'ARRAY', '', '', 1); |