X-Git-Url: https://perl5.git.perl.org/perl5.git/blobdiff_plain/e6b54db65c0cdda6ff40959415e828972b6a92b5..5778acb683d3de419b2dfba40a650762eeedaa14:/hv.h diff --git a/hv.h b/hv.h index 2eea477..95dde46 100644 --- a/hv.h +++ b/hv.h @@ -81,6 +81,8 @@ struct mro_meta { U32 pkg_gen; /* Bumps when local methods/@ISA change */ const struct mro_alg *mro_which; /* which mro alg is in use? */ HV *isa; /* Everything this class @ISA */ + HV *super; /* SUPER method cache */ + U32 destroy_gen; /* Generation number of DESTROY cache */ }; #define MRO_GET_PRIVATE_DATA(smeta, which) \ @@ -111,14 +113,18 @@ struct xpvhv_aux { */ I32 xhv_name_count; struct mro_meta *xhv_mro_meta; - HV * xhv_super; /* SUPER method cache */ #ifdef PERL_HASH_RANDOMIZE_KEYS U32 xhv_rand; /* random value for hash traversal */ U32 xhv_last_rand; /* last random value for hash traversal, used to detect each() after insert for warnings */ #endif + U32 xhv_fill_lazy; + U32 xhv_aux_flags; /* assorted extra flags */ }; +#define HvAUXf_SCAN_STASH 0x1 /* stash is being scanned by gv_check */ +#define HvAUXf_NO_DEREF 0x2 /* @{}, %{} etc (and nomethod) not present */ + /* hash structure: */ /* This structure must match the beginning of struct xpvmg in sv.h. */ struct xpvhv { @@ -134,7 +140,7 @@ struct xpvhv { =for apidoc AmU||HEf_SVKEY This flag, used in the length slot of hash entries and magic structures, specifies the structure contains an C pointer where a C pointer -is to be expected. (For information only--not to be used). +is to be expected. (For information only--not to be used). =head1 Handy Values @@ -156,10 +162,10 @@ Returns the length of the stash's name. Returns true if the name is in UTF8 encoding. =for apidoc Am|char*|HvENAME|HV* stash -Returns the effective name of a stash, or NULL if there is none. The +Returns the effective name of a stash, or NULL if there is none. The effective name represents a location in the symbol table where this stash -resides. It is updated automatically when packages are aliased or deleted. -A stash that is no longer in the symbol table has no effective name. This +resides. It is updated automatically when packages are aliased or deleted. +A stash that is no longer in the symbol table has no effective name. This name is preferable to C for use in MRO linearisations and isa caches. @@ -170,7 +176,7 @@ Returns the length of the stash's effective name. Returns true if the effective name is in UTF8 encoding. =for apidoc Am|void*|HeKEY|HE* he -Returns the actual pointer stored in the key slot of the hash entry. The +Returns the actual pointer stored in the key slot of the hash entry. The pointer may be either C or C, depending on the value of C. Can be assigned to. The C or C macros are usually preferable for finding the value of a key. @@ -178,11 +184,12 @@ usually preferable for finding the value of a key. =for apidoc Am|STRLEN|HeKLEN|HE* he If this is negative, and amounts to C, it indicates the entry holds an C key. Otherwise, holds the actual length of the key. Can -be assigned to. The C macro is usually preferable for finding key +be assigned to. The C macro is usually preferable for finding key lengths. =for apidoc Am|SV*|HeVAL|HE* he -Returns the value slot (type C) stored in the hash entry. Can be assigned +Returns the value slot (type C) +stored in the hash entry. Can be assigned to. SV *foo= HeVAL(hv); @@ -200,14 +207,14 @@ not care about what the length of the key is, you may use the global variable C, though this is rather less efficient than using a local variable. Remember though, that hash keys in perl are free to contain embedded nulls, so using C or similar is not a good way to find -the length of hash keys. This is very similar to the C macro -described elsewhere in this document. See also C. +the length of hash keys. This is very similar to the C macro +described elsewhere in this document. See also C. If you are using C to get values to pass to C to create a new SV, you should consider using C as it is more efficient. -=for apidoc Am|char*|HeUTF8|HE* he +=for apidoc Am|U32|HeUTF8|HE* he Returns whether the C value returned by C is encoded in UTF-8, doing any necessary dereferencing of possibly C keys. The value returned will be 0 or non-0, not necessarily 1 (or even a value with any low bits set), @@ -232,6 +239,18 @@ C. #define PERL_HASH_DEFAULT_HvMAX 7 +/* During hsplit(), if HvMAX(hv)+1 (the new bucket count) is >= this value, + * we preallocate the HvAUX() struct. + * The assumption being that we are using so much space anyway we might + * as well allocate the extra bytes and speed up later keys() + * or each() operations. We don't do this to small hashes as we assume + * that a) it will be easy/fast to resize them to add the iterator, and b) that + * many of them will be objects which won't be traversed. Larger hashes however + * will take longer to extend, and the size of the aux struct is swamped by the + * overall length of the bucket array. + * */ +#define PERL_HV_ALLOC_AUX_SIZE (1 << 9) + /* these hash entry flags ride on hent_klen (for use only in magic/tied HVs) */ #define HEf_SVKEY -2 /* hent_key is an SV* */ @@ -239,7 +258,7 @@ C. # define Nullhv Null(HV*) #endif #define HvARRAY(hv) ((hv)->sv_u.svu_hash) -#define HvFILL(hv) Perl_hv_fill(aTHX_ (const HV *)(hv)) +#define HvFILL(hv) Perl_hv_fill(aTHX_ MUTABLE_HV(hv)) #define HvMAX(hv) ((XPVHV*) SvANY(hv))->xhv_max /* This quite intentionally does no flag checking first. That's your responsibility. */ @@ -365,7 +384,9 @@ C. ((HeKLEN(he) == HEf_SVKEY) ? \ HeKEY_sv(he) : \ newSVpvn_flags(HeKEY(he), \ - HeKLEN(he), SVs_TEMP)) : \ + HeKLEN(he), \ + SVs_TEMP | \ + ( HeKUTF8(he) ? SVf_UTF8 : 0 ))) : \ &PL_sv_undef) #define HeSVKEY_set(he,sv) ((HeKLEN(he) = HEf_SVKEY), (HeKEY_sv(he) = sv)) @@ -466,6 +487,22 @@ C. (MUTABLE_SV(hv_common_key_len((hv), (key), (klen), \ (flags) | HV_DELETE, NULL, 0))) +#ifdef PERL_CORE +# define hv_storehek(hv, hek, val) \ + hv_common((hv), NULL, HEK_KEY(hek), HEK_LEN(hek), HEK_UTF8(hek), \ + HV_FETCH_ISSTORE|HV_FETCH_JUST_SV, (val), HEK_HASH(hek)) +# define hv_fetchhek(hv, hek, lval) \ + ((SV **) \ + hv_common((hv), NULL, HEK_KEY(hek), HEK_LEN(hek), HEK_UTF8(hek), \ + (lval) \ + ? (HV_FETCH_JUST_SV | HV_FETCH_LVALUE) \ + : HV_FETCH_JUST_SV, \ + NULL, HEK_HASH(hek))) +# define hv_deletehek(hv, hek, flags) \ + hv_common((hv), NULL, HEK_KEY(hek), HEK_LEN(hek), HEK_UTF8(hek), \ + (flags)|HV_DELETE, NULL, HEK_HASH(hek)) +#endif + /* This refcounted he structure is used for storing the hints used for lexical pragmas. Without threads, it's basically struct he + refcount. With threads, life gets more complex as the structure needs to be shared