diff options
author | Nicholas Clark <nick@ccl4.org> | 2021-09-12 08:44:52 +0000 |
---|---|---|
committer | Craig A. Berry <craigberry@mac.com> | 2021-09-15 16:24:06 -0500 |
commit | d5a0a5dd15db7407246717e8c3e8891b9ba7c53c (patch) | |
tree | dc6c0a224a72d26aac913d171dae5729beb6a8e4 /hv.c | |
parent | e893e12ccfed2a8d5f0649a8cc133249ca7373ff (diff) | |
download | perl-d5a0a5dd15db7407246717e8c3e8891b9ba7c53c.tar.gz |
Simplify the code related to prime_env_iter().
Of the platforms that define DYNAMIC_ENV_FETCH, prime_env_iter() is only
needed on VMS, so only call it on VMS. Previously we defined a dummy stub on
Win32 (with PERL_IMPLICIT_SYS defined), and did something different again
for __riscos__.
Remove the dummy definition for win32, and change the conditional compilation
to only call prime_env_iter() on VMS. This removes a call to mg_find() on
Win32, which likely can't be optimised away, as the compiler cannot know that
it has no side effects.
Because`iter` points to a structure immediately after of HvARRAY(), it needs
updating if HvARRAY() has moved because it has been expanded.
Code was added for VMS in Aug 2005 to address this bug with commit
03026e68943709ca:
[patch@25334] hv.c vms environment fix.
From: "John E. Malmberg" <wb8tyw@qsl.net>
Message-ID: <4310F552.8050401@qsl.net>
see https://www.nntp.perl.org/group/perl.perl5.porters/2005/08/msg104261.html
However, the comment added in that code wasn't entirely accurate. The
iteration count doesn't need to be *reset* because prior to that first call
to prime_env_iter() there would be no entries in the hash. In fact, the
iterator *had* to be in its "reset" state - entry == NULL - to enter the
if block. Also, as prime_env_iter() only adds hash values but does not
change the hash's iterator state, it can't change iter->xhv_eiter. Hence
there's no need to re-read *that* value, is it will still be NULL.
Hence the only action needed is to re-initialise iter from HvAUX(), as the
structure it needs to point to has likely been moved in memory by the hash
stores performed by prime_env_iter().
Diffstat (limited to 'hv.c')
-rw-r--r-- | hv.c | 8 |
1 files changed, 2 insertions, 6 deletions
@@ -2733,18 +2733,14 @@ Perl_hv_iternext_flags(pTHX_ HV *hv, I32 flags) return NULL; } } -#if defined(DYNAMIC_ENV_FETCH) && !defined(__riscos__) /* set up %ENV for iteration */ +#if defined(DYNAMIC_ENV_FETCH) && defined(VMS) /* set up %ENV for iteration */ if (!entry && SvRMAGICAL((const SV *)hv) && mg_find((const SV *)hv, PERL_MAGIC_env)) { prime_env_iter(); -#ifdef VMS /* The prime_env_iter() on VMS just loaded up new hash values - * so the iteration count needs to be reset back to the beginning + * so HvARRAY() liked has been reallocated */ - hv_iterinit(hv); iter = HvAUX(hv); - oldentry = entry = iter->xhv_eiter; /* HvEITER(hv) */ -#endif } #endif |