From d3148f758506efd28325dfd8e1b698385133f0cd Mon Sep 17 00:00:00 2001 From: Todd Rinaldo Date: Thu, 13 Oct 2016 22:38:31 -0500 Subject: 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] --- hv.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'hv.h') 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. #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. */ -- cgit v1.2.1