Fixed inaccurate compiler error when ternary operator is involved (
bug 5711, r=dvander).
1 #ifndef _INCLUDE_KNIGHT_KE_SECTOR_STACK_H_
2 #define _INCLUDE_KNIGHT_KE_SECTOR_STACK_H_
4 #include <KnightAllocator.h>
13 static const size_t DEFAULT_SECTOR_SIZE = 64;
15 KeSectorStack() : m_SectorSize(DEFAULT_SECTOR_SIZE), m_UsedSize(0), m_MaxUsedSize(0)
20 KeSectorStack(size_t sectorSize) : m_SectorSize(sectorSize), m_UsedSize(0), m_MaxUsedSize(0)
25 KeSectorStack(size_t sectorSize, ke_allocator_t *alloc) :
26 m_SectorSize(sectorSize), m_UsedSize(0), m_pAlloc(alloc), m_MaxUsedSize(0)
39 size_t last_sector_item;
41 if (m_MaxUsedSize == 0)
46 last_sector = (m_MaxUsedSize - 1) / m_SectorSize;
47 last_sector_item = (m_MaxUsedSize - 1) % m_SectorSize;
49 for (size_t i = 0; i < last_sector; i++)
51 sector = m_Sectors[i];
53 for (size_t j = 0; j < m_SectorSize; j++)
59 sector = m_Sectors[last_sector];
60 for (size_t i = 0; i <= last_sector_item; i++)
70 for (size_t i = 0; i < m_Sectors.size(); i++)
72 free_sector(m_Sectors[i]);
80 return (m_UsedSize == 0) ? true : false;
83 void push(const T & val)
85 if ((m_UsedSize / m_SectorSize) >= m_Sectors.size())
87 /* Create a new sector */
92 sector = (T *)malloc(sizeof(T) * m_SectorSize);
96 sector = (T *)m_pAlloc->alloc(m_pAlloc, sizeof(T) * m_SectorSize);
99 m_Sectors.push_back(sector);
102 at(m_UsedSize) = val;
106 /* Keep track of the maximum used size so we can defer the
107 * massive destruction job until the end.
109 if (m_UsedSize > m_MaxUsedSize)
111 m_MaxUsedSize = m_UsedSize;
127 return at(m_UsedSize - 1);
138 return m_Sectors[x / m_SectorSize][x % m_SectorSize];
141 void free_sector(T * sector)
143 if (m_pAlloc == NULL)
147 else if (m_pAlloc->dealloc != NULL)
149 m_pAlloc->dealloc(m_pAlloc, sector);
154 KeVector<T *> m_Sectors;
157 ke_allocator_t *m_pAlloc;
158 size_t m_MaxUsedSize;
162 #endif //_INCLUDE_KNIGHT_KE_SECTOR_STACK_H_