aboutsummaryrefslogtreecommitdiff
path: root/parse.c
diff options
context:
space:
mode:
authorAndrew Chambers <[email protected]>2021-10-13 16:40:38 +1300
committerAndrew Chambers <[email protected]>2021-10-13 16:40:38 +1300
commit92c7930bf2f2cfeea51991524384bf6ce226bd7a (patch)
treea3e659fd80b183d2e44075fc1668bcb7fb72414f /parse.c
parent7bce4e2fda947c9503cf74dc0446170aa976cb41 (diff)
Remove padding from some structs, add comment to cache.
Diffstat (limited to 'parse.c')
-rw-r--r--parse.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/parse.c b/parse.c
index 591e8eb..b272121 100644
--- a/parse.c
+++ b/parse.c
@@ -2,9 +2,18 @@
/* Maintain a direct mapped cache of Parsev*. */
static const Parsev *internparsev(Parsev *p) {
- /* An extremely simple direct mapped cache of *Parsev,
- It relies on direct pointer comparison, which
- itself only works because our pointers are interned. */
+ /*
+ A simple direct mapped cache that prevents our parser
+ from allocating duplicate values. Note that it uses memcmp
+ for equality, even on pointer values, this works because the
+ pointers themselves are also interned.
+
+ This simplicity somes with one big cost - Parsev variants with padding
+ can trigger a false positive on valgrind. It should still safe
+ because reading these undefined bytes do not change the behavior of the
+ program. The best fix is still to avoid the padding bytes in the Parsev
+ variant layout using a tool such as 'pahole'.
+ */
size_t idx;
const Parsev *interned;
static const Parsev *cache[4096] = {0};