ref: b1269ab53a1158cd233a3ccd517a5bd6d6f2f850
parent: 3ecd169cd6f9d53e341efdbecb906357443b6bcf
author: YamaArashi <[email protected]>
date: Wed Aug 20 22:57:43 EDT 2014
Improve rgbasm performance
--- a/include/asm/symbol.h
+++ b/include/asm/symbol.h
@@ -3,7 +3,7 @@
#include "asm/types.h"
-#define HASHSIZE 73
+#define HASHSIZE (1 << 16)
#define MAXSYMLEN 256
struct sSymbol {
@@ -35,6 +35,7 @@
#define SYMF_CONST 0x200 /* symbol has a constant value, will
* not be changed during linking */
+ULONG calchash(char *s);
void sym_PrepPass1(void);
void sym_PrepPass2(void);
void sym_AddLocalReloc(char *tzSym);
--- a/src/asm/output.c
+++ b/src/asm/output.c
@@ -43,6 +43,7 @@
ULONG ID;
struct sSymbol *pSymbol;
struct PatchSymbol *pNext;
+ struct PatchSymbol *pBucketNext; // next symbol in hash table bucket
};
struct SectionStackEntry {
@@ -56,8 +57,10 @@
*
*/
+struct PatchSymbol *tHashedPatchSymbols[HASHSIZE];
struct Section *pSectionList = NULL, *pCurrentSection = NULL;
struct PatchSymbol *pPatchSymbols = NULL;
+struct PatchSymbol **ppPatchSymbolsTail = &pPatchSymbols;
char tzObjectname[_MAX_PATH];
struct SectionStackEntry *pSectionStack = NULL;
@@ -327,17 +330,16 @@
addsymbol(struct sSymbol * pSym)
{
struct PatchSymbol *pPSym, **ppPSym;
- ULONG ID = 0;
+ static ULONG nextID = 0;
+ ULONG hash;
- pPSym = pPatchSymbols;
- ppPSym = &(pPatchSymbols);
+ hash = calchash(pSym->tzName);
+ ppPSym = &(tHashedPatchSymbols[hash]);
- while (pPSym) {
- if (pSym == pPSym->pSymbol)
- return (pPSym->ID);
- ppPSym = &(pPSym->pNext);
- pPSym = pPSym->pNext;
- ID += 1;
+ while ((*ppPSym) != NULL) {
+ if (pSym == (*ppPSym)->pSymbol)
+ return (*ppPSym)->ID;
+ ppPSym = &((*ppPSym)->pBucketNext);
}
if ((*ppPSym = pPSym =
@@ -344,13 +346,16 @@
(struct PatchSymbol *) malloc(sizeof(struct PatchSymbol))) !=
NULL) {
pPSym->pNext = NULL;
+ pPSym->pBucketNext = NULL;
pPSym->pSymbol = pSym;
- pPSym->ID = ID;
- return (ID);
+ pPSym->ID = nextID++;
} else
fatalerror("No memory for patchsymbol");
- return ((ULONG) - 1);
+ *ppPatchSymbolsTail = pPSym;
+ ppPatchSymbolsTail = &(pPSym->pNext);
+
+ return pPSym->ID;
}
/*
* RGBAsm - OUTPUT.C - Outputs an objectfile
@@ -385,23 +390,17 @@
struct Patch *
allocpatch(void)
{
- struct Patch *pPatch, **ppPatch;
+ struct Patch *pPatch;
- pPatch = pCurrentSection->pPatches;
- ppPatch = &(pCurrentSection->pPatches);
-
- while (pPatch) {
- ppPatch = &(pPatch->pNext);
- pPatch = pPatch->pNext;
- }
-
- if ((*ppPatch = pPatch =
+ if ((pPatch =
(struct Patch *) malloc(sizeof(struct Patch))) != NULL) {
- pPatch->pNext = NULL;
+ pPatch->pNext = pCurrentSection->pPatches;
pPatch->nRPNSize = 0;
pPatch->pRPN = NULL;
} else
fatalerror("No memory for patch");
+
+ pCurrentSection->pPatches = pPatch;
return (pPatch);
}
--- a/src/asm/symbol.c
+++ b/src/asm/symbol.c
@@ -75,10 +75,10 @@
ULONG
calchash(char *s)
{
- ULONG hash = 0;
+ ULONG hash = 5381;
while (*s != 0)
- hash += (*s++);
+ hash = (hash * 33) ^ (*s++);
return (hash % HASHSIZE);
}