X-Git-Url: https://perl5.git.perl.org/perl5.git/blobdiff_plain/ddbc26e57f1b560af69ffe5b3f09ba053923edae..e9e9e546c6762874da180492e33c78382c00e560:/hv.h?ds=sidebyside diff --git a/hv.h b/hv.h index 6062522..c249b8f 100644 --- a/hv.h +++ b/hv.h @@ -58,7 +58,7 @@ struct shared_he { /* Subject to change. Don't access this directly. - Use the funcs in mro.c + Use the funcs in mro_core.c */ struct mro_alg { @@ -119,8 +119,12 @@ struct xpvhv_aux { 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 { @@ -136,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 @@ -148,20 +152,20 @@ Null HV pointer. =head1 Hash Manipulation Functions =for apidoc Am|char*|HvNAME|HV* stash -Returns the package name of a stash, or NULL if C isn't a stash. -See C, C. +Returns the package name of a stash, or C if C isn't a stash. +See C>, C>. =for apidoc Am|STRLEN|HvNAMELEN|HV *stash Returns the length of the stash's name. =for apidoc Am|unsigned char|HvNAMEUTF8|HV *stash -Returns true if the name is in UTF8 encoding. +Returns true if the name is in UTF-8 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. @@ -169,10 +173,10 @@ caches. Returns the length of the stash's effective name. =for apidoc Am|unsigned char|HvENAMEUTF8|HV *stash -Returns true if the effective name is in UTF8 encoding. +Returns true if the effective name is in UTF-8 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. @@ -180,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); @@ -202,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), @@ -234,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* */ @@ -471,6 +488,16 @@ C. (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)) @@ -602,11 +629,5 @@ Creates a new HV. The reference count is set to 1. #include "hv_func.h" /* - * Local variables: - * c-indentation-style: bsd - * c-basic-offset: 4 - * indent-tabs-mode: nil - * End: - * * ex: set ts=8 sts=4 sw=4 et: */