Scripting: Remove needless heap allocations

This commit is contained in:
Vicki Pfau 2024-12-31 03:11:31 -08:00
parent 72ee6f9840
commit 23531e24b8
1 changed files with 24 additions and 7 deletions

View File

@ -834,21 +834,38 @@ static void _scriptDebuggerEntered(struct mDebuggerModule* debugger, enum mDebug
};
cbInfo.type->alloc(&cbInfo);
// TODO: Intern strings
mScriptTableInsert(&cbInfo, mScriptStringCreateFromASCII("address"), mScriptValueCreateFromUInt(info->address));
static struct mScriptValue keyAddress = mSCRIPT_MAKE_CHARP("address");
static struct mScriptValue keyWidth = mSCRIPT_MAKE_CHARP("width");
static struct mScriptValue keySegment = mSCRIPT_MAKE_CHARP("segment");
static struct mScriptValue keyOldValue = mSCRIPT_MAKE_CHARP("oldValue");
static struct mScriptValue keyNewValue = mSCRIPT_MAKE_CHARP("newValue");
static struct mScriptValue keyAccessType = mSCRIPT_MAKE_CHARP("accessType");
struct mScriptValue valAddress = mSCRIPT_MAKE_U32(info->address);
struct mScriptValue valWidth = mSCRIPT_MAKE_S32(info->width);
struct mScriptValue valSegment = mSCRIPT_MAKE_S32(info->segment);
struct mScriptValue valOldValue;
struct mScriptValue valNewValue;
struct mScriptValue valAccessType;
mScriptTableInsert(&cbInfo, &keyAddress, &valAddress);
if (info->width > 0) {
mScriptTableInsert(&cbInfo, mScriptStringCreateFromASCII("width"), mScriptValueCreateFromSInt(info->width));
mScriptTableInsert(&cbInfo, &keyWidth, &valWidth);
}
if (info->segment >= 0) {
mScriptTableInsert(&cbInfo, mScriptStringCreateFromASCII("segment"), mScriptValueCreateFromSInt(info->segment));
mScriptTableInsert(&cbInfo, &keySegment, &valSegment);
}
if (reason == DEBUGGER_ENTER_WATCHPOINT) {
mScriptTableInsert(&cbInfo, mScriptStringCreateFromASCII("oldValue"), mScriptValueCreateFromSInt(info->type.wp.oldValue));
valOldValue = mSCRIPT_MAKE_S32(info->type.wp.oldValue);
valNewValue = mSCRIPT_MAKE_S32(info->type.wp.newValue);
valAccessType = mSCRIPT_MAKE_S32(info->type.wp.accessType);
mScriptTableInsert(&cbInfo, &keyOldValue, &valOldValue);
if (info->type.wp.accessType != WATCHPOINT_READ) {
mScriptTableInsert(&cbInfo, mScriptStringCreateFromASCII("newValue"), mScriptValueCreateFromSInt(info->type.wp.newValue));
mScriptTableInsert(&cbInfo, &keyNewValue, &valNewValue);
}
mScriptTableInsert(&cbInfo, mScriptStringCreateFromASCII("accessType"), mScriptValueCreateFromSInt(info->type.wp.accessType));
mScriptTableInsert(&cbInfo, &keyAccessType, &valAccessType);
}
_runCallbacks(scriptDebugger, point, &cbInfo);