String interning, forgot file
This commit is contained in:
23
src/text_editor/intern_table.cpp
Normal file
23
src/text_editor/intern_table.cpp
Normal 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;
|
||||||
Reference in New Issue
Block a user