mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-23 03:22:08 +00:00
Improve rgbasm performance
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
/*
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user