Skip to content

Commit

Permalink
Merge pull request #107 from Arkshine/Fix-array-compatibility-issue
Browse files Browse the repository at this point in the history
Fix a compatibility issue with the "reserved" parameter.
  • Loading branch information
Arkshine committed Aug 7, 2014
2 parents 6a24935 + 72b514c commit a7d94a4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
20 changes: 7 additions & 13 deletions amxmodx/datastructs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,31 +35,25 @@ static cell AMX_NATIVE_CALL ArrayCreate(AMX* amx, cell* params)
return -1;
}

if (reserved < 0)
{
reserved = 0;
}

// Scan through the vector list to see if any are NULL.
// NULL means the vector was previously destroyed.
for (unsigned int i=0; i < VectorHolder.length(); ++i)
{
if (VectorHolder[i]==NULL)
{
VectorHolder[i] = new CellArray(cellsize);

if (reserved > 0)
{
VectorHolder[i]->resize(reserved);
}

VectorHolder[i] = new CellArray(cellsize, reserved);
return i + 1;
}
}

// None are NULL, create a new vector
CellArray* NewVector = new CellArray(cellsize);
CellArray* NewVector = new CellArray(cellsize, reserved);

if (reserved > 0)
{
NewVector->resize(reserved);
}

VectorHolder.append(NewVector);

return VectorHolder.length();
Expand Down
5 changes: 3 additions & 2 deletions amxmodx/datastructs.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
class CellArray
{
public:
CellArray(size_t blocksize) : m_Data(NULL), m_BlockSize(blocksize), m_AllocSize(0), m_Size(0)
CellArray(size_t blocksize, size_t basesize = 0) : m_Data(NULL), m_BlockSize(blocksize), m_AllocSize(0), m_BaseSize(basesize > 0 ? basesize : 8), m_Size(0)
{
}

Expand Down Expand Up @@ -160,7 +160,7 @@ class CellArray
/* Set a base allocation size of 8 items */
if (!m_AllocSize)
{
m_AllocSize = 8;
m_AllocSize = m_BaseSize;
}
/* If it's not enough, keep doubling */
while (m_Size + count > m_AllocSize)
Expand All @@ -181,6 +181,7 @@ class CellArray
cell *m_Data;
size_t m_BlockSize;
size_t m_AllocSize;
size_t m_BaseSize;
size_t m_Size;
};

Expand Down

0 comments on commit a7d94a4

Please sign in to comment.