From 9680a18e05d8ad975454d837dcd73d2fa328b365 Mon Sep 17 00:00:00 2001 From: Syed Daanish Date: Fri, 21 Aug 2026 21:36:28 +0100 Subject: [PATCH] Decrease memory footprint of storing blocks. --- include/internal/syntax/decl.h | 6 +++--- src/internal/syntax/parser.cc | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/include/internal/syntax/decl.h b/include/internal/syntax/decl.h index 654ea9f..a6e542c 100644 --- a/include/internal/syntax/decl.h +++ b/include/internal/syntax/decl.h @@ -121,9 +121,9 @@ struct ParseStateLeaf : ParseState { void *state; uint32_t n; uint32_t cap; - uint32_t *blocks; - static constexpr uint32_t IS_CLOSING = 1ull << 31; - static constexpr uint32_t LINE_MASK = ~IS_CLOSING; + uint16_t *blocks; + static constexpr uint16_t IS_CLOSING = 0x8000; + static constexpr uint16_t LINE_MASK = 0x7fff; }; struct TreeCursor { diff --git a/src/internal/syntax/parser.cc b/src/internal/syntax/parser.cc index 16aae73..76382d9 100644 --- a/src/internal/syntax/parser.cc +++ b/src/internal/syntax/parser.cc @@ -248,10 +248,10 @@ void Parser::modify(vase::Vase &vase, uint64_t target, uint64_t count) { continue; if (c.leaf->n == c.leaf->cap) { uint32_t cap = c.leaf->cap ? c.leaf->cap * 2 : 8; - c.leaf->blocks = (uint32_t *)realloc(c.leaf->blocks, cap * sizeof(uint32_t)); + c.leaf->blocks = (uint16_t *)realloc(c.leaf->blocks, cap * sizeof(uint16_t)); c.leaf->cap = cap; } - c.leaf->blocks[c.leaf->n++] = t << 31 | (at - chunk_start); + c.leaf->blocks[c.leaf->n++] = t << 15 | (at - chunk_start); } at++; } @@ -269,7 +269,7 @@ uint64_t Parser::next_closing(uint64_t line) { while (c.leaf) { auto *leaf = c.leaf; for (uint32_t i = 0; i < leaf->n; ++i) { - uint32_t block = leaf->blocks[i]; + uint16_t block = leaf->blocks[i]; uint32_t pos = block & ParseStateLeaf::LINE_MASK; if (first_leaf && pos <= relative) continue; @@ -300,7 +300,7 @@ uint64_t Parser::prev_opening(uint64_t line) { while (c.leaf) { auto *leaf = c.leaf; for (int32_t i = (int32_t)leaf->n - 1; i >= 0; --i) { - uint32_t block = leaf->blocks[i]; + uint16_t block = leaf->blocks[i]; uint32_t pos = block & ParseStateLeaf::LINE_MASK; if (first_leaf && pos >= relative) continue;