summaryrefslogtreecommitdiff
path: root/val.c
diff options
context:
space:
mode:
Diffstat (limited to 'val.c')
-rw-r--r--val.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/val.c b/val.c
index 355aac6..530737d 100644
--- a/val.c
+++ b/val.c
@@ -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;
}