String interning, forgot file

This commit is contained in:
Krzosa Karol
2024-08-08 11:50:30 +02:00
parent 4434cd5764
commit d47482bc04

View File

@@ -0,0 +1,23 @@
struct InternTable {
Table<String> strings;
Arena *arena;
};
String Intern(InternTable *table, String string) {
if (table->arena == NULL) {
table->arena = AllocArena();
table->strings.allocator = *table->arena;
}
String *value = table->strings.get(string);
if (!value) {
String copy = Copy(*table->arena, string);
table->strings.put(copy, copy);
return copy;
}
return *value;
}
// We use the intern table to optimize for space, I don't want to worry about freeing
// buffer names and event text data so let it all accumulate and interning will at least
// optimize worst offenders (like event text)
InternTable GlobalInternTable;