diff options
author | Sergey Andreenko <seandree@microsoft.com> | 2018-12-22 22:42:44 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-12-22 22:42:44 -0800 |
commit | 47c5949c83d05080bcd360c274855017bb3f9576 (patch) | |
tree | 39df42c3b06b5569e58ed31805e565ba9f32a5cd /src/jit/arraystack.h | |
parent | a43ac609fc1706b8174c3568f797dce8a81a192f (diff) | |
download | coreclr-47c5949c83d05080bcd360c274855017bb3f9576.tar.gz coreclr-47c5949c83d05080bcd360c274855017bb3f9576.tar.bz2 coreclr-47c5949c83d05080bcd360c274855017bb3f9576.zip |
Fix ArrayStack's call to default constructor for <T>. (#21624)
* Add ArrayStack::Empty
* Add ArrayStack::BottomRef
* Delete unused `ReverseTop`.
* do not use default constructor.
Diffstat (limited to 'src/jit/arraystack.h')
-rw-r--r-- | src/jit/arraystack.h | 51 |
1 files changed, 19 insertions, 32 deletions
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<T>(initialCapacity); } else { maxIndex = builtinSize; - data = builtinData; + data = reinterpret_cast<T*>(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<T>(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)]; }; |