diff --git a/src/text_editor/intern_table.cpp b/src/text_editor/intern_table.cpp new file mode 100644 index 0000000..5d65adf --- /dev/null +++ b/src/text_editor/intern_table.cpp @@ -0,0 +1,23 @@ +struct InternTable { + Table 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; \ No newline at end of file