diff options
author | ubq323 <ubq323@ubq323.website> | 2023-08-05 04:15:17 +0100 |
---|---|---|
committer | ubq323 <ubq323@ubq323.website> | 2023-08-05 04:15:20 +0100 |
commit | 9ee73a8459eb2bb58adc29da02de312b7e4e7dca (patch) | |
tree | f41bddde050c61e254af8ba4c53a3bc11ca7b804 /val.c | |
parent | 93fe66fb8ef5c731b46a30a804f74b4bf3b133d7 (diff) |
refactor hashtables, and use objstrings for keys
doesn't yet work without string interning, which will require
further refactoring
Diffstat (limited to 'val.c')
-rw-r--r-- | val.c | 14 |
1 files changed, 13 insertions, 1 deletions
@@ -2,15 +2,27 @@ #include <string.h> #include "val.h" #include "mem.h" +#include "ht.h" -ObjString *objstring_new(char *src, size_t len) { +ObjString *objstring_copy(char *src, size_t len) { char *d = NEW_ARR(char, 1+len); memcpy(d, src, len); d[len] = '\0'; ObjString *o = NEW_OBJ(ObjString, OTY_STRING); o->len = len; o->b = d; + o->hash = hash(d, len); + + return o; +} + +ObjString *objstring_take(char *src, size_t len) { + ObjString *o = NEW_OBJ(ObjString, OTY_STRING); + o->len = len; + o->b = src; + o->hash = hash(src, len); + return o; } |