Decrease memory footprint of storing blocks.
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user