Skip to content

Commit decc832

Browse files
committed
doc-links(cs): the lookup memo holds no memory until a step is remembered
A memo is made for every file that has references, and most files ask few using steps: its table and arena are now opened by the first step it keeps (8 KB arena block, 16-entry table), not when the file starts. Outcomes and work counts are unchanged. Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
1 parent cc2c966 commit decc832

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

‎src/pipeline/doc_links_cs.c‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4664,11 +4664,11 @@ struct cs_memo {
46644664

46654665
enum { CS_MEMO_KEY = CS_NAME_BUF + CBM_SZ_128 };
46664666

4667+
/* Holds no memory until the first step is remembered: most files ask few
4668+
* using steps, and a memo is made for every file that has references. */
46674669
static void memo_init(cs_memo_t *m) {
46684670
memset(m, 0, sizeof(*m));
4669-
cbm_arena_init(&m->arena);
4670-
m->steps = cbm_ht_create(CBM_SZ_256);
4671-
m->off = m->steps == NULL;
4671+
cbm_arena_init_lazy(&m->arena, CBM_ARENA_APPEND_BLOCK);
46724672
}
46734673

46744674
static void memo_destroy(cs_memo_t *m) {
@@ -4688,14 +4688,21 @@ static bool memo_key(char *buf, size_t cap, const cs_ctx_t *c, int region, int u
46884688

46894689
static bool memo_get(const cs_memo_t *m, const char *key, cs_found_t *out) {
46904690
cs_work(SKIP_ONE);
4691-
const cs_found_t *hit = (const cs_found_t *)cbm_ht_get(m->steps, key);
4691+
const cs_found_t *hit = m->steps ? (const cs_found_t *)cbm_ht_get(m->steps, key) : NULL;
46924692
if (hit) {
46934693
*out = *hit;
46944694
}
46954695
return hit != NULL;
46964696
}
46974697

46984698
static void memo_put(cs_memo_t *m, const char *key, const cs_found_t *step) {
4699+
if (!m->steps) {
4700+
m->steps = cbm_ht_create(CBM_SZ_16);
4701+
if (!m->steps) {
4702+
m->off = true;
4703+
return;
4704+
}
4705+
}
46994706
char *k = cbm_arena_strdup(&m->arena, key);
47004707
cs_found_t *v = (cs_found_t *)cbm_arena_alloc(&m->arena, sizeof(*v));
47014708
if (!k || !v) {

0 commit comments

Comments
 (0)