diff options
| author | 2022-09-02 11:11:04 +0200 | |
|---|---|---|
| committer | 2022-09-02 11:11:04 +0200 | |
| commit | 88066fc3b0638281024293d8d8e6a25896090e71 (patch) | |
| tree | 9d72efb0587645f40626a4516f5b51796fd4799a | |
| parent | 173ed4524ecb47c90302f4bebbee96e10adacb99 (diff) | |
use arena for interning strings
| -rw-r--r-- | src/util.cff | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/src/util.cff b/src/util.cff index c56486b..23fa13e 100644 --- a/src/util.cff +++ b/src/util.cff @@ -1,8 +1,8 @@ import "util.hff"; import "cffc.hff"; import "set.hff"; -import "mem.hff"; import "common.hff"; +import "mem.hff"; extern fn xmalloc(n usize) *void { let p = malloc(n); @@ -80,7 +80,13 @@ extern fn internstr(s *const u8) *const u8 { fn eq(a *const u8, b *const u8) bool { return a != #null and b != #null and streq(a, b); } - fn dup(s *const u8) *const u8 { return xstrdup(s); } + fn dup(s *const u8) *const u8 { + static arena Arena = {}; + let n = strlen(s) + 1; + let p = Arena:allocf(&arena, n, 1); + memcpy(p, s, n); + return p; + } }> = {}; return *set->intern(s); } |