Skip to content

Commit 07735c1

Browse files
authored
Remove use of HeapAlloc and HeapPop. (#2455)
1 parent 6739b0c commit 07735c1

2 files changed

Lines changed: 6 additions & 21 deletions

File tree

core/logic/smn_sorting.cpp

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include <stdlib.h>
3333
#include <string.h>
3434
#include <time.h>
35+
#include <memory>
3536
#include "common_logic.h"
3637
#include "CellArray.h"
3738
#include <IHandleSys.h>
@@ -227,16 +228,10 @@ static cell_t sm_SortStrings_Legacy(IPluginContext *pContext, const cell_t *para
227228
pContext->LocalToPhysAddr(params[1], &array);
228229

229230
/** HACKHACK - back up the old indices, replace the indices with something easier */
230-
cell_t amx_addr, *phys_addr;
231-
int err;
232-
if ((err=pContext->HeapAlloc(array_size, &amx_addr, &phys_addr)) != SP_ERROR_NONE)
233-
{
234-
pContext->ThrowNativeErrorEx(err, "Ran out of memory to sort");
235-
return 0;
236-
}
231+
auto phys_addr = std::make_unique<cell_t[]>(array_size);
237232

238233
g_CurStringArray = array;
239-
g_CurRebaseMap = phys_addr;
234+
g_CurRebaseMap = phys_addr.get();
240235

241236
for (int i=0; i<array_size; i++)
242237
{
@@ -268,8 +263,6 @@ static cell_t sm_SortStrings_Legacy(IPluginContext *pContext, const cell_t *para
268263
array[i] = ((char *)&array[array[i]] + phys_addr[array[i]]) - (char *)&array[i];
269264
}
270265

271-
pContext->HeapPop(amx_addr);
272-
273266
g_CurStringArray = NULL;
274267
g_CurRebaseMap = NULL;
275268

@@ -449,13 +442,7 @@ static cell_t sm_SortCustom2D_Legacy(IPluginContext *pContext, const cell_t *par
449442
}
450443

451444
/** back up the old indices, replace the indices with something easier */
452-
cell_t amx_addr, *phys_addr;
453-
int err;
454-
if ((err=pContext->HeapAlloc(array_size, &amx_addr, &phys_addr)) != SP_ERROR_NONE)
455-
{
456-
pContext->ThrowNativeErrorEx(err, "Ran out of memory to sort");
457-
return 0;
458-
}
445+
auto phys_addr = std::make_unique<cell_t[]>(array_size);
459446

460447
sort_info oldinfo = g_SortInfo;
461448

@@ -467,7 +454,7 @@ static cell_t sm_SortCustom2D_Legacy(IPluginContext *pContext, const cell_t *par
467454

468455
/** Same process as in strings, back up the old indices for later fixup */
469456
g_SortInfo.array_base = array;
470-
g_SortInfo.array_remap = phys_addr;
457+
g_SortInfo.array_remap = phys_addr.get();
471458

472459
for (int i=0; i<array_size; i++)
473460
{
@@ -486,8 +473,6 @@ static cell_t sm_SortCustom2D_Legacy(IPluginContext *pContext, const cell_t *par
486473
array[i] = ((char *)&array[array[i]] + phys_addr[array[i]]) - (char *)&array[i];
487474
}
488475

489-
pContext->HeapPop(amx_addr);
490-
491476
g_SortInfo = oldinfo;
492477

493478
return 1;

0 commit comments

Comments
 (0)