Skip to content

Commit

Permalink
Revert some changes and add new one.
Browse files Browse the repository at this point in the history
  • Loading branch information
intorr committed Dec 9, 2017
1 parent 6f70821 commit 8139105
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions src/xrCore/FixedMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,6 @@ class FixedMAP
K key;
T val;
TNode *left, *right;

TNode() : key(), val(), left(nullptr), right(nullptr) {}

static void *operator new (size_t size) { return allocator::alloc(size); }
static void *operator new[](size_t size) { return allocator::alloc(size); }
static void operator delete (void *block) { allocator::dealloc(block); }
static void operator delete[](void *block) { allocator::dealloc(block); }
};
typedef void __fastcall callback(TNode*);
typedef bool __fastcall callback_cmp(TNode& N1, TNode& N2);
Expand All @@ -32,14 +25,15 @@ class FixedMAP
u32 pool;
u32 limit;

IC u32 Size(u32 Count) { return Count * sizeof(TNode); }
void Realloc()
{
u32 newLimit = limit + SG_REALLOC_ADVANCE;
VERIFY(newLimit % SG_REALLOC_ADVANCE == 0);
TNode* newNodes = new TNode[newLimit];
TNode* newNodes = (TNode*)allocator::alloc(sizeof(TNode) * newLimit);
VERIFY(newNodes);

for (TNode* cur = newNodes + limit; cur != newNodes + newLimit; cur++)
new(cur) TNode();
if (limit)
std::copy(nodes, nodes + limit, newNodes);

Expand All @@ -61,7 +55,7 @@ class FixedMAP
}
}
if (nodes)
delete[] nodes;
allocator::dealloc(nodes);

nodes = newNodes;
limit = newLimit;
Expand Down Expand Up @@ -145,7 +139,11 @@ class FixedMAP
void destroy()
{
if (nodes)
delete[] nodes;
{
for (TNode* cur = begin(); cur != end(); cur++)
cur->~TNode();
allocator::dealloc(nodes);
}
nodes = 0;
pool = 0;
limit = 0;
Expand Down

0 comments on commit 8139105

Please sign in to comment.