char string[1]; /* Null-terminated string. */
};
/* All interned strings. */
static struct hmap interns = HMAP_INITIALIZER (interns);
char string[1]; /* Null-terminated string. */
};
/* All interned strings. */
static struct hmap interns = HMAP_INITIALIZER (interns);
static struct interned_string *
intern_lookup__ (const char *s, size_t length, unsigned int hash)
{
struct interned_string *is;
HMAP_FOR_EACH_WITH_HASH (is, struct interned_string, node, hash, &interns)
static struct interned_string *
intern_lookup__ (const char *s, size_t length, unsigned int hash)
{
struct interned_string *is;
HMAP_FOR_EACH_WITH_HASH (is, struct interned_string, node, hash, &interns)
is = xmalloc (length + sizeof *is);
hmap_insert (&interns, &is->node, hash);
is->ref_cnt = 1;
is = xmalloc (length + sizeof *is);
hmap_insert (&interns, &is->node, hash);
is->ref_cnt = 1;
memcpy (is->string, s, length + 1);
}
return is->string;
}
static struct interned_string *
memcpy (is->string, s, length + 1);
}
return is->string;
}
static struct interned_string *
struct interned_string *is = UP_CAST (s, struct interned_string, string);
assert (is->ref_cnt > 0);
return is;
struct interned_string *is = UP_CAST (s, struct interned_string, string);
assert (is->ref_cnt > 0);
return is;
unsigned int hash = hash_bytes (s, length, 0);
return intern_lookup__ (s, length, hash) != NULL;
}
unsigned int hash = hash_bytes (s, length, 0);
return intern_lookup__ (s, length, hash) != NULL;
}