mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-22 11:12:07 +00:00
Avoid unnecessary copies in symbol init
This commit is contained in:
@@ -94,7 +94,7 @@ void sym_SetMacroArgID(uint32_t nMacroCount);
|
|||||||
void sym_AddMacro(char *tzSym, int32_t nDefLineNo);
|
void sym_AddMacro(char *tzSym, int32_t nDefLineNo);
|
||||||
void sym_Ref(char *tzSym);
|
void sym_Ref(char *tzSym);
|
||||||
void sym_ShiftCurrentMacroArgs(void);
|
void sym_ShiftCurrentMacroArgs(void);
|
||||||
void sym_AddString(char *tzSym, char *tzValue);
|
void sym_AddString(char *tzSym, char const *tzValue);
|
||||||
uint32_t sym_GetDefinedValue(char *s);
|
uint32_t sym_GetDefinedValue(char *s);
|
||||||
void sym_Purge(char *tzName);
|
void sym_Purge(char *tzName);
|
||||||
bool sym_IsRelocDiffDefined(char *tzSym1, char *tzSym2);
|
bool sym_IsRelocDiffDefined(char *tzSym1, char *tzSym2);
|
||||||
|
|||||||
@@ -49,22 +49,6 @@ static char SavedMINUTE[3];
|
|||||||
static char SavedSECOND[3];
|
static char SavedSECOND[3];
|
||||||
static bool exportall;
|
static bool exportall;
|
||||||
|
|
||||||
void helper_RemoveLeadingZeros(char *string)
|
|
||||||
{
|
|
||||||
char *new_beginning = string;
|
|
||||||
|
|
||||||
while (*new_beginning == '0')
|
|
||||||
new_beginning++;
|
|
||||||
|
|
||||||
if (new_beginning == string)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (*new_beginning == '\0')
|
|
||||||
new_beginning--;
|
|
||||||
|
|
||||||
memmove(string, new_beginning, strlen(new_beginning) + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t Callback_NARG(unused_ struct sSymbol *sym)
|
int32_t Callback_NARG(unused_ struct sSymbol *sym)
|
||||||
{
|
{
|
||||||
uint32_t i = 0;
|
uint32_t i = 0;
|
||||||
@@ -473,7 +457,7 @@ void sym_AddEqu(char *tzSym, int32_t value)
|
|||||||
* of the string are enough: sym_AddString("M_PI", "3.1415"). This is the same
|
* of the string are enough: sym_AddString("M_PI", "3.1415"). This is the same
|
||||||
* as ``` M_PI EQUS "3.1415" ```
|
* as ``` M_PI EQUS "3.1415" ```
|
||||||
*/
|
*/
|
||||||
void sym_AddString(char *tzSym, char *tzValue)
|
void sym_AddString(char *tzSym, char const *tzValue)
|
||||||
{
|
{
|
||||||
struct sSymbol *nsym = createNonrelocSymbol(tzSym);
|
struct sSymbol *nsym = createNonrelocSymbol(tzSym);
|
||||||
|
|
||||||
@@ -710,6 +694,17 @@ void sym_SetExportAll(uint8_t set)
|
|||||||
exportall = set;
|
exportall = set;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a pointer to the first non-zero character in a string
|
||||||
|
* Non-'0', not non-'\0'.
|
||||||
|
*/
|
||||||
|
static inline char const *removeLeadingZeros(char const *ptr)
|
||||||
|
{
|
||||||
|
while (*ptr == '0')
|
||||||
|
ptr++;
|
||||||
|
return ptr;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Initialize the symboltable
|
* Initialize the symboltable
|
||||||
*/
|
*/
|
||||||
@@ -760,28 +755,23 @@ void sym_Init(void)
|
|||||||
time_utc);
|
time_utc);
|
||||||
|
|
||||||
strftime(SavedYEAR, sizeof(SavedYEAR), "%Y", time_utc);
|
strftime(SavedYEAR, sizeof(SavedYEAR), "%Y", time_utc);
|
||||||
/* This cannot start with zeros */
|
|
||||||
strftime(SavedMONTH, sizeof(SavedMONTH), "%m", time_utc);
|
strftime(SavedMONTH, sizeof(SavedMONTH), "%m", time_utc);
|
||||||
helper_RemoveLeadingZeros(SavedMONTH);
|
|
||||||
strftime(SavedDAY, sizeof(SavedDAY), "%d", time_utc);
|
strftime(SavedDAY, sizeof(SavedDAY), "%d", time_utc);
|
||||||
helper_RemoveLeadingZeros(SavedDAY);
|
|
||||||
strftime(SavedHOUR, sizeof(SavedHOUR), "%H", time_utc);
|
strftime(SavedHOUR, sizeof(SavedHOUR), "%H", time_utc);
|
||||||
helper_RemoveLeadingZeros(SavedHOUR);
|
|
||||||
strftime(SavedMINUTE, sizeof(SavedMINUTE), "%M", time_utc);
|
strftime(SavedMINUTE, sizeof(SavedMINUTE), "%M", time_utc);
|
||||||
helper_RemoveLeadingZeros(SavedMINUTE);
|
|
||||||
strftime(SavedSECOND, sizeof(SavedSECOND), "%S", time_utc);
|
strftime(SavedSECOND, sizeof(SavedSECOND), "%S", time_utc);
|
||||||
helper_RemoveLeadingZeros(SavedSECOND);
|
|
||||||
|
|
||||||
sym_AddString("__TIME__", SavedTIME);
|
sym_AddString("__TIME__", SavedTIME);
|
||||||
sym_AddString("__DATE__", SavedDATE);
|
sym_AddString("__DATE__", SavedDATE);
|
||||||
sym_AddString("__ISO_8601_LOCAL__", SavedTIMESTAMP_ISO8601_LOCAL);
|
sym_AddString("__ISO_8601_LOCAL__", SavedTIMESTAMP_ISO8601_LOCAL);
|
||||||
sym_AddString("__ISO_8601_UTC__", SavedTIMESTAMP_ISO8601_UTC);
|
sym_AddString("__ISO_8601_UTC__", SavedTIMESTAMP_ISO8601_UTC);
|
||||||
sym_AddString("__UTC_DAY__", SavedDAY);
|
/* This cannot start with zeros */
|
||||||
sym_AddString("__UTC_MONTH__", SavedMONTH);
|
|
||||||
sym_AddString("__UTC_YEAR__", SavedYEAR);
|
sym_AddString("__UTC_YEAR__", SavedYEAR);
|
||||||
sym_AddString("__UTC_HOUR__", SavedHOUR);
|
sym_AddString("__UTC_MONTH__", removeLeadingZeros(SavedMONTH));
|
||||||
sym_AddString("__UTC_MINUTE__", SavedMINUTE);
|
sym_AddString("__UTC_DAY__", removeLeadingZeros(SavedDAY));
|
||||||
sym_AddString("__UTC_SECOND__", SavedSECOND);
|
sym_AddString("__UTC_HOUR__", removeLeadingZeros(SavedHOUR));
|
||||||
|
sym_AddString("__UTC_MINUTE__", removeLeadingZeros(SavedMINUTE));
|
||||||
|
sym_AddString("__UTC_SECOND__", removeLeadingZeros(SavedSECOND));
|
||||||
|
|
||||||
pScope = NULL;
|
pScope = NULL;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user