Fix inefficient string management

This commit is contained in:
Ryan Dwyer
2023-05-08 22:07:42 +10:00
parent c693fd78b1
commit 2c7cc32d5e
5 changed files with 15 additions and 14 deletions
+1 -1
View File
@@ -960,7 +960,7 @@ static Gfx *amRenderSlot(Gfx *gdl, char *text, s16 x, s16 y, s32 mode, s32 flags
paddingbottom = 3;
}
if (text == NULL || strcmp(text, "") == 0) {
if (text == NULL || text[0] == '\0') {
return gdl;
}
+1 -1
View File
@@ -314,7 +314,7 @@ void amTick(void)
amGetSlotDetails(slotnum, &flags, text);
if (strcmp(text, "") == 0) {
if (text[0] == '\0') {
gotoslot = false;
}
+4 -5
View File
@@ -528,7 +528,7 @@ static void menuCalculateItemSize(struct menuitem *item, s16 *width, s16 *height
case MENUITEMTYPE_DROPDOWN:
text = menuResolveParam2Text(item);
if (text && strcmp(text, "") == 0) {
if (text && text[0] == '\0') {
*width = 0;
*height = 0;
} else {
@@ -582,7 +582,7 @@ static void menuCalculateItemSize(struct menuitem *item, s16 *width, s16 *height
if (text == NULL) {
*width = 120;
} else if (strcmp(text, "") == 0) {
} else if (text[0] == '\0') {
*width = 0;
*height = 0;
} else {
@@ -630,7 +630,7 @@ static void menuCalculateItemSize(struct menuitem *item, s16 *width, s16 *height
font = g_FontHandelGothicMd;
}
if (strcmp(text, "") == 0) {
if (text[0] == '\0') {
*height = 0;
*width = *height;
} else {
@@ -650,8 +650,7 @@ static void menuCalculateItemSize(struct menuitem *item, s16 *width, s16 *height
if ((item->flags & (MENUITEMFLAG_LABEL_HASRIGHTTEXT | MENUITEMFLAG_BIGFONT)) == 0) {
text = menuResolveText(item->param3, item);
// @bug: This is not how you check for an empty string
if (text != NULL && text != "") {
if (text != NULL) {
textMeasure(&textheight, &textwidth, text, chars, font, 0);
*width += textwidth + 5;
+8 -6
View File
@@ -1895,8 +1895,7 @@ static Gfx *menuitemLabelRender(Gfx *gdl, struct menurendercontext *context)
// Right side text
text = menuResolveText(context->item->param3, context->item);
// This is not how you check if a string is empty...
if (text != NULL && text != "") {
if (text != NULL) {
s32 textheight;
s32 textwidth;
@@ -2114,8 +2113,7 @@ static Gfx *menuitemSelectableRender(Gfx *gdl, struct menurendercontext *context
// Right side text
text = menuResolveText(context->item->param3, context->item);
// This is not how you check if a string is empty...
if (text != NULL && text != "") {
if (text != NULL) {
s32 textheight;
s32 textwidth;
@@ -2653,7 +2651,7 @@ static char *menuitemScrollableGetText(u32 type)
*/
static Gfx *menuitemScrollableRender(Gfx *gdl, struct menurendercontext *context)
{
char alltext[8000] = "";
char alltext[8000];
char headingtext[8000];
char bodytext[8000];
bool prevwaslinebreak;
@@ -2667,6 +2665,8 @@ static Gfx *menuitemScrollableRender(Gfx *gdl, struct menurendercontext *context
char *rawtext;
s32 paddingright = 24;
alltext[0] = '\0';
rawtext = menuitemScrollableGetText(context->item->param);
if (menuIsScrollableUnscrollable(context->item)) {
@@ -2764,7 +2764,7 @@ static bool menuitemScrollableTick(struct menuitem *item, struct menudialog *dia
u32 stack;
if ((s16)dialog->height != data->scrollable.unk06) {
char wrapped[8000] = "";
char wrapped[8000];
char *rawtext;
s32 width;
s32 height;
@@ -2773,6 +2773,8 @@ static bool menuitemScrollableTick(struct menuitem *item, struct menudialog *dia
s16 colwidth;
s16 rowheight;
wrapped[0] = '\0';
dialogFindItem(dialog, item, &rowindex, &colindex);
colwidth = g_Menus[g_MpPlayerNum].cols[colindex].width;
+1 -1
View File
@@ -14802,7 +14802,7 @@ static void weaponGetPickupText(char *buffer, s32 weaponnum, bool dual)
void currentPlayerQueuePickupWeaponHudmsg(u32 weaponnum, bool dual)
{
char buffer[100] = "";
char buffer[100];
weaponGetPickupText(buffer, weaponnum, dual);
hudmsgCreateWithFlags(buffer, HUDMSGTYPE_DEFAULT, HUDMSGFLAG_ONLYIFALIVE | HUDMSGFLAG_ALLOWDUPES);