summary refs log tree commit diff
path: root/parse.c
diff options
context:
space:
mode:
authorQuentin Carbonneaux <quentin@c9x.me>2017-05-17 09:40:07 -0400
committerQuentin Carbonneaux <quentin@c9x.me>2017-05-17 10:05:28 -0400
commita3a1451c5fabb5c94f7fbeb13fdc6b1e2c23181f (patch)
tree1fb1ba60e8f3cab09c629ce9dd63e00e01974c39 /parse.c
parent2d02070af019e9896ecf2a63bedc098092fd395d (diff)
downloadroux-a3a1451c5fabb5c94f7fbeb13fdc6b1e2c23181f.tar.gz
intern symbol names
Symbols in the source file are still limited in
length because the rest of the code assumes that
strings always fit in NString bytes.

Regardless, there is already a benefit because
comparing/copying symbol names does not require
using strcmp()/strcpy() anymore.
Diffstat (limited to 'parse.c')
-rw-r--r--parse.c17
1 files changed, 3 insertions, 14 deletions
diff --git a/parse.c b/parse.c
index b7bab5b..f4d4909 100644
--- a/parse.c
+++ b/parse.c
@@ -143,17 +143,6 @@ err(char *s, ...)
 	exit(1);
 }
 
-static inline uint32_t
-hash(char *s)
-{
-	uint32_t h;
-
-	h = 0;
-	for (; *s; ++s)
-		h = *s + 17*h;
-	return h;
-}
-
 static void
 lexinit()
 {
@@ -394,12 +383,12 @@ parseref()
 		goto Look;
 	case Tglo:
 		c.type = CAddr;
-		strcpy(c.label, tokval.str);
+		c.label = intern(tokval.str);
 	Look:
 		for (i=0; i<curf->ncon; i++)
 			if (curf->con[i].type == c.type
 			&& curf->con[i].bits.i == c.bits.i
-			&& strcmp(curf->con[i].label, c.label) == 0)
+			&& curf->con[i].label == c.label)
 				return CON(i);
 		vgrow(&curf->con, ++curf->ncon);
 		curf->con[i] = c;
@@ -1091,7 +1080,7 @@ printcon(Con *c, FILE *f)
 	case CUndef:
 		break;
 	case CAddr:
-		fprintf(f, "$%s", c->label);
+		fprintf(f, "$%s", str(c->label));
 		if (c->bits.i)
 			fprintf(f, "%+"PRIi64, c->bits.i);
 		break;