From 47c5949c83d05080bcd360c274855017bb3f9576 Mon Sep 17 00:00:00 2001 From: Sergey Andreenko Date: Sat, 22 Dec 2018 22:42:44 -0800 Subject: Fix ArrayStack's call to default constructor for . (#21624) * Add ArrayStack::Empty * Add ArrayStack::BottomRef * Delete unused `ReverseTop`. * do not use default constructor. --- src/jit/arraystack.h | 51 +++++++++++++++++++-------------------------------- 1 file changed, 19 insertions(+), 32 deletions(-) (limited to 'src/jit/arraystack.h') diff --git a/src/jit/arraystack.h b/src/jit/arraystack.h index 2565e19856..60f01351d2 100644 --- a/src/jit/arraystack.h +++ b/src/jit/arraystack.h @@ -11,17 +11,17 @@ class ArrayStack static const int builtinSize = 8; public: - ArrayStack(CompAllocator alloc, int initialSize = builtinSize) : m_alloc(alloc) + ArrayStack(CompAllocator alloc, int initialCapacity = builtinSize) : m_alloc(alloc) { - if (initialSize > builtinSize) + if (initialCapacity > builtinSize) { - maxIndex = initialSize; - data = new (alloc) T[initialSize]; + maxIndex = initialCapacity; + data = m_alloc.allocate(initialCapacity); } else { maxIndex = builtinSize; - data = builtinData; + data = reinterpret_cast(builtinData); } tosIndex = 0; @@ -56,7 +56,7 @@ public: // and copy over T* oldData = data; noway_assert(maxIndex * 2 > maxIndex); - data = new (m_alloc) T[maxIndex * 2]; + data = m_alloc.allocate(maxIndex * 2); for (int i = 0; i < maxIndex; i++) { data[i] = oldData[i]; @@ -64,31 +64,6 @@ public: maxIndex *= 2; } - // reverse the top N in the stack - void ReverseTop(int number) - { - if (number < 2) - { - return; - } - - assert(number <= tosIndex); - - int start = tosIndex - number; - int offset = 0; - while (offset < number / 2) - { - T temp; - int index = start + offset; - int otherIndex = tosIndex - 1 - offset; - temp = data[index]; - data[index] = data[otherIndex]; - data[otherIndex] = temp; - - offset++; - } - } - T Pop() { assert(tosIndex > 0); @@ -127,6 +102,11 @@ public: return tosIndex; } + bool Empty() + { + return tosIndex == 0; + } + // return the bottom of the stack T Bottom() { @@ -141,6 +121,13 @@ public: return data[indx]; } + // return a reference to the i'th from the bottom + T BottomRef(int indx) + { + assert(tosIndex > indx); + return data[indx]; + } + void Reset() { tosIndex = 0; @@ -152,5 +139,5 @@ private: int maxIndex; T* data; // initial allocation - T builtinData[builtinSize]; + char builtinData[builtinSize * sizeof(T)]; }; -- cgit v1.2.3