summaryrefslogtreecommitdiff
path: root/hv.h
diff options
context:
space:
mode:
authorTodd Rinaldo <toddr@cpan.org>2016-10-13 22:38:31 -0500
committerYves Orton <demerphq@gmail.com>2016-10-24 17:36:21 +0200
commitd3148f758506efd28325dfd8e1b698385133f0cd (patch)
tree1a83f9a2cb70eeabf727a77db9244d267716ec87 /hv.h
parent92c843fb4b4e1a1e0ac7ec0fe198dc77266838da (diff)
downloadperl-d3148f758506efd28325dfd8e1b698385133f0cd.tar.gz
hv.h: rework HEK_FLAGS to a proper member in struct hek
Move the store of HEK_FLAGS off the end of the allocated hek_key into the hek struct, simplifying access and providing clarity to the code. What is not clear is why Nicholas or perhaps Jarkko did not do this themselves. We use similar tricks elsewhere, so perhaps it was just continuing a tradition... One thought is that we often have do strcmp/memeq on these strings, and having their start be aligned might improve performance, wheras this patch changes them to be unaligned. If so perhaps we should just make flags a U32 and let the HEK's be larger. They are shared in PL_strtab, and are probably often sitting in malloc blocks that are sufficiently large enough that making them bigger would make no practical difference. (All of this is worth checking.) [with edits by Yves Orton]
Diffstat (limited to 'hv.h')
-rw-r--r--hv.h5
1 files changed, 2 insertions, 3 deletions
diff --git a/hv.h b/hv.h
index ee536f08c8..16634b7e44 100644
--- a/hv.h
+++ b/hv.h
@@ -45,10 +45,9 @@ struct he {
struct hek {
U32 hek_hash; /* hash of key */
I32 hek_len; /* length of hash key */
+ char hek_flags; /* The flags associated with this key */
char hek_key[1]; /* variable-length hash key */
/* the hash-key is \0-terminated */
- /* after the \0 there is a byte for flags, such as whether the key
- is UTF-8 */
};
struct shared_he {
@@ -397,7 +396,7 @@ C<SV*>.
#define HEK_HASH(hek) (hek)->hek_hash
#define HEK_LEN(hek) (hek)->hek_len
#define HEK_KEY(hek) (hek)->hek_key
-#define HEK_FLAGS(hek) (*((unsigned char *)(HEK_KEY(hek))+HEK_LEN(hek)+1))
+#define HEK_FLAGS(hek) (hek)->hek_flags
#define HVhek_UTF8 0x01 /* Key is utf8 encoded. */
#define HVhek_WASUTF8 0x02 /* Key is bytes here, but was supplied as utf8. */