allocate temporary state label strings from the compiler backend's allocator.

They share appoximate lifetime so this gets rid of 3 more copystring calls.
This commit is contained in:
Christoph Oelckers 2023-10-08 11:40:34 +02:00
parent c8ee0cd5cc
commit 4f5df7b9ef

View file

@ -40,6 +40,7 @@
#include "thingdef.h" #include "thingdef.h"
#include "r_state.h" #include "r_state.h"
#include "templates.h" #include "templates.h"
#include "codegen.h"
// stores indices for symbolic state labels for some old-style DECORATE functions. // stores indices for symbolic state labels for some old-style DECORATE functions.
@ -702,7 +703,7 @@ void FStateDefinitions::RetargetStatePointers (intptr_t count, const char *targe
} }
else else
{ {
statelist[i].State = (FState *)copystring (target); statelist[i].State = (FState *)FxAlloc.Strdup(target);
statelist[i].DefineFlags = SDF_LABEL; statelist[i].DefineFlags = SDF_LABEL;
} }
} }
@ -803,7 +804,6 @@ FState *FStateDefinitions::ResolveGotoLabel (PClassActor *mytype, char *name)
{ {
Printf (TEXTCOLOR_RED "Attempt to get invalid state %s from actor %s.\n", label, type->TypeName.GetChars()); Printf (TEXTCOLOR_RED "Attempt to get invalid state %s from actor %s.\n", label, type->TypeName.GetChars());
} }
delete[] namestart; // free the allocated string buffer
return state; return state;
} }
@ -867,7 +867,7 @@ bool FStateDefinitions::SetGotoLabel(const char *string)
// copy the text - this must be resolved later! // copy the text - this must be resolved later!
if (laststate != NULL) if (laststate != NULL)
{ // Following a state definition: Modify it. { // Following a state definition: Modify it.
laststate->NextState = (FState*)copystring(string); laststate->NextState = (FState*)FxAlloc.Strdup(string);
laststate->DefineFlags = SDF_LABEL; laststate->DefineFlags = SDF_LABEL;
laststatebeforelabel = NULL; laststatebeforelabel = NULL;
return true; return true;
@ -877,7 +877,7 @@ bool FStateDefinitions::SetGotoLabel(const char *string)
RetargetStates (lastlabel+1, string); RetargetStates (lastlabel+1, string);
if (laststatebeforelabel != NULL) if (laststatebeforelabel != NULL)
{ {
laststatebeforelabel->NextState = (FState*)copystring(string); laststatebeforelabel->NextState = (FState*)FxAlloc.Strdup(string);
laststatebeforelabel->DefineFlags = SDF_LABEL; laststatebeforelabel->DefineFlags = SDF_LABEL;
laststatebeforelabel = NULL; laststatebeforelabel = NULL;
} }