shithub: scc

Download patch

ref: dc646368f83872d8a5a3f3470254f9516e5e09dc
parent: 02fbd9d0cb5ff557a59d1114ee1343c87ee9dd51
author: Roberto E. Vargas Caballero <[email protected]>
date: Mon Feb 20 03:43:54 EST 2017

[cc1] Move labels to a different hash table

--- a/cc1/symbol.c
+++ b/cc1/symbol.c
@@ -11,6 +11,8 @@
 #include "cc1.h"
 
 #define NR_SYM_HASH 64
+#define NR_CPP_HASH 32
+#define NR_LBL_HASH 16
 
 unsigned curctx;
 static unsigned short counterid;
@@ -17,7 +19,8 @@
 
 static Symbol *head, *labels;
 static Symbol *htab[NR_SYM_HASH];
-static Symbol *htabcpp[NR_SYM_HASH];
+static Symbol *htabcpp[NR_CPP_HASH];
+static Symbol *htablbl[NR_LBL_HASH];
 
 #ifndef NDEBUG
 void
@@ -54,15 +57,27 @@
 static Symbol **
 hash(char *s, int ns)
 {
-	unsigned c, h;
+	unsigned c, h, size;
 	Symbol **tab;
 
 	for (h = 0; c = *s; ++s)
 		h = h*33 ^ c;
-	h &= NR_SYM_HASH-1;
 
-	tab = (ns == NS_CPP) ? htabcpp : htab;
-	return &tab[h];
+	switch (ns) {
+	case NS_CPP:
+		tab = htabcpp;
+		size = NR_CPP_HASH-1;
+		break;
+	case NS_LABEL:
+		tab = htablbl;
+		size = NR_LBL_HASH-1;
+		break;
+	default:
+		tab = htab;
+		size = NR_SYM_HASH-1;
+		break;
+	}
+	return &tab[h & size];
 }
 
 static void