77#include < cassert>
88
99
10- bool TlsfAllocator::checkIfSecondLevelEmpty (size_t firstLevelIndex) const
10+ bool TlsfAllocator::checkIfSecondLevelEmpty (const size_t firstLevelIndex) const
1111{
1212
13- // To check if Second Level Bitmap of a particular First level is empty
14- // TODO : Write code just to check if its zero no need for calling getLeastSetBitIndex()
15-
1613
1714
1815 if (firstLevelIndex >= sizeof (m_firstLevelBitmap) * 8 ) // bits
1916 {
2017 return true ;// returning true because index is out of bounds
2118 }
2219
23- const LeastSetBitIndexResult leastSetBitIndexResult = getLeastSetBitIndex (m_secondLevelBitmap[firstLevelIndex]);
24-
25- if (!leastSetBitIndexResult.found )
26- {
27- return true ;
28- }
29-
30- return false ;
3120
21+ return m_secondLevelBitmap[firstLevelIndex] == 0 ;
3222
3323
3424}
@@ -44,7 +34,7 @@ bool TlsfAllocator::checkIfSecondLevelEmpty(size_t firstLevelIndex) const
4434
4535
4636
47- TlsfAllocator::LeastSetBitIndexResult TlsfAllocator::getLeastSetBitIndex (size_t bitmap) const
37+ TlsfAllocator::LeastSetBitIndexResult TlsfAllocator::getLeastSetBitIndex (const size_t bitmap) const
4838{
4939
5040
@@ -80,6 +70,7 @@ TlsfAllocator::LeastSetBitIndexResult TlsfAllocator::getLeastSetBitIndex(size_t
8070
8171#else
8272 // fallback to manual search
73+ // rewrite to use binary search??
8374 setIndex = 0 ;
8475 for (size_t i = 0 ; i < sizeof (bitmap) * 8 ; ++i)
8576 {
@@ -103,7 +94,7 @@ TlsfAllocator::LeastSetBitIndexResult TlsfAllocator::getLeastSetBitIndex(size_t
10394
10495
10596
106- TwoLevelIndex TlsfAllocator::getTwoLevelIndex (size_t size) const
97+ TwoLevelIndex TlsfAllocator::getTwoLevelIndex (const size_t size) const
10798{
10899 TwoLevelIndex index;
109100
@@ -190,8 +181,7 @@ if(!intrinsicFound)
190181
191182
192183
193- TwoLevelIndex TlsfAllocator::getTwoLevelIndexWithFreeBlock (size_t size) const
194-
184+ TwoLevelIndex TlsfAllocator::getTwoLevelIndexWithFreeBlock (const size_t size) const
195185{
196186 TwoLevelIndex twoLevelIndex = getTwoLevelIndex (size);
197187
@@ -892,10 +882,10 @@ TlsfAllocator::~TlsfAllocator()
892882
893883
894884
895- void * TlsfAllocator::allocate (size_t size)
885+ void * TlsfAllocator::allocate (const size_t size)
896886{
897887
898-
888+ assert (size != 0 );
899889
900890 TlsfBlockHeader* allocatedBlock = getFreeBlock (size);
901891
0 commit comments