From b1269ab53a1158cd233a3ccd517a5bd6d6f2f850 Mon Sep 17 00:00:00 2001 From: YamaArashi Date: Thu, 21 Aug 2014 02:57:43 -0700 Subject: [PATCH] Improve rgbasm performance --- include/asm/symbol.h | 3 ++- src/asm/output.c | 45 ++++++++++++++++++++++---------------------- src/asm/symbol.c | 4 ++-- 3 files changed, 26 insertions(+), 26 deletions(-) diff --git a/include/asm/symbol.h b/include/asm/symbol.h index e63aa196..516a5486 100644 --- 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 @@ struct sSymbol { #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); diff --git a/src/asm/output.c b/src/asm/output.c index e39f67d1..c36b0e88 100644 --- a/src/asm/output.c +++ b/src/asm/output.c @@ -43,6 +43,7 @@ struct PatchSymbol { ULONG ID; struct sSymbol *pSymbol; struct PatchSymbol *pNext; + struct PatchSymbol *pBucketNext; // next symbol in hash table bucket }; struct SectionStackEntry { @@ -56,8 +57,10 @@ struct SectionStackEntry { * */ +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,30 +330,32 @@ ULONG 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 = (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,24 +390,18 @@ addexports(void) 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); } /* diff --git a/src/asm/symbol.c b/src/asm/symbol.c index 21a07744..cd51bc85 100644 --- a/src/asm/symbol.c +++ b/src/asm/symbol.c @@ -75,10 +75,10 @@ getvaluefield(struct sSymbol * sym) ULONG calchash(char *s) { - ULONG hash = 0; + ULONG hash = 5381; while (*s != 0) - hash += (*s++); + hash = (hash * 33) ^ (*s++); return (hash % HASHSIZE); }