Skip to content

Commit 9aea53e

Browse files
committed
Follow @AlexPeshkoff suggestions:
removed Allocator from template arguments, removed pointer based ctor in favor of reference based one.
1 parent 67ac091 commit 9aea53e

File tree

16 files changed

+40
-61
lines changed

16 files changed

+40
-61
lines changed

src/common/classes/GenericMap.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ class GenericMap : public AutoStorage
9797
typedef typename KeyValuePair::first_type KeyType;
9898
typedef typename KeyValuePair::second_type ValueType;
9999

100-
typedef BePlusTree<KeyValuePair*, KeyType, MemoryPool, FirstObjectKey<KeyValuePair>, KeyComparator> ValuesTree;
100+
typedef BePlusTree<KeyValuePair*, KeyType, FirstObjectKey<KeyValuePair>, KeyComparator> ValuesTree;
101101
typedef typename ValuesTree::Accessor TreeAccessor;
102102
typedef typename ValuesTree::ConstAccessor ConstTreeAccessor;
103103

@@ -139,10 +139,10 @@ class GenericMap : public AutoStorage
139139
friend class Accessor;
140140
friend class ConstAccessor;
141141

142-
GenericMap() : tree(&getPool()), mCount(0) { }
142+
GenericMap() : tree(getPool()), mCount(0) { }
143143

144144
explicit GenericMap(MemoryPool& a_pool)
145-
: AutoStorage(a_pool), tree(&getPool()), mCount(0)
145+
: AutoStorage(a_pool), tree(getPool()), mCount(0)
146146
{ }
147147

148148
~GenericMap()

src/common/classes/sparse_bitmap.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,12 @@ class SparseBitmap : public AutoStorage
6060
public:
6161
// Default constructor, stack placement
6262
SparseBitmap() :
63-
singular(false), singular_value(0), tree(&getPool()), defaultAccessor(this)
63+
singular(false), singular_value(0), tree(getPool()), defaultAccessor(this)
6464
{ }
6565

6666
// Pooled constructor
6767
explicit SparseBitmap(MemoryPool& p) :
68-
AutoStorage(p), singular(false), singular_value(0), tree(&getPool()), defaultAccessor(this)
68+
AutoStorage(p), singular(false), singular_value(0), tree(getPool()), defaultAccessor(this)
6969
{ }
7070

7171
// Default accessor methods
@@ -225,7 +225,7 @@ class SparseBitmap : public AutoStorage
225225
}
226226
};
227227

228-
typedef BePlusTree<Bucket, T, MemoryPool, Bucket> BitmapTree;
228+
typedef BePlusTree<Bucket, T, Bucket> BitmapTree;
229229
typedef typename BitmapTree::Accessor BitmapTreeAccessor;
230230

231231
// Set if bitmap contains a single value only

src/common/classes/tree.h

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -93,24 +93,20 @@ enum LocType { locEqual, locLess, locGreat, locGreatEqual, locLessEqual };
9393
// an indexed dynamic array without increase of algorithm calculation costs (this is one
9494
// more classical B+ tree feature). This is also not done to improve tree performance a little
9595
//
96-
template <typename Value, typename Key = Value, typename Allocator = Firebird::MemoryPool,
97-
typename KeyOfValue = DefaultKeyValue<Value>,
98-
typename Cmp = DefaultComparator<Key> >
96+
template <typename Value, typename Key = Value,
97+
typename KeyOfValue = DefaultKeyValue<Value>,
98+
typename Cmp = DefaultComparator<Key> >
9999
class BePlusTree
100100
{
101101
static const FB_SIZE_T LEAF_COUNT = LEAF_PAGE_SIZE / sizeof(Value);
102102
static const FB_SIZE_T NODE_COUNT = NODE_PAGE_SIZE / sizeof(void*);
103103
public:
104-
explicit BePlusTree(Allocator *_pool)
105-
: pool(_pool), level(0), defaultAccessor(this)
106-
{ }
107-
108-
explicit BePlusTree(Allocator& _pool)
104+
explicit BePlusTree(Firebird::MemoryPool& _pool)
109105
: pool(&_pool), level(0), defaultAccessor(this)
110106
{ }
111107

112-
BePlusTree(Allocator *_pool, const BePlusTree& from)
113-
: pool(_pool), level(0), defaultAccessor(this)
108+
BePlusTree(Firebird::MemoryPool& _pool, const BePlusTree& from)
109+
: pool(&_pool), level(0), defaultAccessor(this)
114110
{
115111
append(from);
116112
}
@@ -283,9 +279,6 @@ class BePlusTree
283279
}
284280

285281
private:
286-
BePlusTree(Allocator *_pool, void *rootPage) : pool(_pool), level(0),
287-
root(new(rootPage) ItemList()), defaultAccessor(this) {}
288-
289282
class NodeList;
290283

291284
class ItemList : public SortedVector<Value, LEAF_COUNT, Key, KeyOfValue, Cmp>
@@ -641,22 +634,18 @@ class BePlusTree
641634
}; // class Accessor
642635

643636
private:
644-
Allocator* pool;
637+
Firebird::MemoryPool* const pool;
645638
int level;
646639
NodePtr root;
647640
Accessor defaultAccessor;
648641

649642
void _removePage(int level, NodePtr node);
650-
651-
friend class MemoryPool;
652-
friend class NodeList;
653-
friend class Accessor;
654643
};
655644

656645
// ************************ BePlusTree implementation ******************
657646

658-
template <typename Value, typename Key, typename Allocator, typename KeyOfValue, typename Cmp>
659-
bool BePlusTree<Value, Key, Allocator, KeyOfValue, Cmp>::add(const Value& item, Accessor* accessor)
647+
template <typename Value, typename Key, typename KeyOfValue, typename Cmp>
648+
bool BePlusTree<Value, Key, KeyOfValue, Cmp>::add(const Value& item, Accessor* accessor)
660649
{
661650
// Finish initialization of the tree if necessary
662651
if (!root)
@@ -894,8 +883,8 @@ bool BePlusTree<Value, Key, Allocator, KeyOfValue, Cmp>::add(const Value& item,
894883
return true;
895884
}
896885

897-
template <typename Value, typename Key, typename Allocator, typename KeyOfValue, typename Cmp>
898-
void BePlusTree<Value, Key, Allocator, KeyOfValue, Cmp>::_removePage(const int nodeLevel, NodePtr node)
886+
template <typename Value, typename Key, typename KeyOfValue, typename Cmp>
887+
void BePlusTree<Value, Key, KeyOfValue, Cmp>::_removePage(const int nodeLevel, NodePtr node)
899888
{
900889
NodeList *list;
901890
// Get parent and adjust the links

src/jrd/GarbageCollector.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class GarbageCollector
7070
return item.pageno;
7171
}
7272
};
73-
typedef Firebird::BePlusTree<PageTran, ULONG, MemoryPool, PageTran> PageTranMap;
73+
typedef Firebird::BePlusTree<PageTran, ULONG, PageTran> PageTranMap;
7474

7575

7676
class RelationData

src/jrd/Savepoint.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ namespace Jrd
7373
const Format* m_format;
7474
};
7575

76-
typedef Firebird::BePlusTree<UndoItem, SINT64, MemoryPool, UndoItem> UndoItemTree;
76+
typedef Firebird::BePlusTree<UndoItem, SINT64, UndoItem> UndoItemTree;
7777

7878
class VerbAction
7979
{

src/jrd/TempSpace.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ class TempSpace : public Firebird::File
209209
Firebird::Array<UCHAR> initialBuffer;
210210
bool initiallyDynamic;
211211

212-
typedef Firebird::BePlusTree<Segment, offset_t, MemoryPool, Segment> FreeSegmentTree;
212+
typedef Firebird::BePlusTree<Segment, offset_t, Segment> FreeSegmentTree;
213213
FreeSegmentTree freeSegments;
214214

215215
static Firebird::GlobalPtr<Firebird::Mutex> initMutex;

src/jrd/extds/ExtDS.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,8 +262,7 @@ class Provider : public Firebird::GlobalStorage
262262
}
263263
};
264264

265-
typedef Firebird::BePlusTree<AttToConn, AttToConn, Firebird::MemoryPool,
266-
AttToConn, AttToConn>
265+
typedef Firebird::BePlusTree<AttToConn, AttToConn, AttToConn, AttToConn>
267266
AttToConnMap;
268267

269268
AttToConnMap m_connections;

src/jrd/nbak.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,7 @@ bool BackupManager::actualizeAlloc(thread_db* tdbb, bool haveGlobalLock)
638638
// For SuperServer this routine is really executed only at database startup when
639639
// it has exlock or when exclusive access to database is enabled
640640
if (!alloc_table)
641-
alloc_table = FB_NEW_POOL(*database->dbb_permanent) AllocItemTree(database->dbb_permanent);
641+
alloc_table = FB_NEW_POOL(*database->dbb_permanent) AllocItemTree(*database->dbb_permanent);
642642

643643
while (true)
644644
{

src/jrd/nbak.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class AllocItem
8282
}
8383
};
8484

85-
typedef Firebird::BePlusTree<AllocItem, ULONG, MemoryPool, AllocItem> AllocItemTree;
85+
typedef Firebird::BePlusTree<AllocItem, ULONG, AllocItem> AllocItemTree;
8686

8787
// Class to synchronize access to backup state
8888

src/jrd/req.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ const USHORT RPB_CLEAR_FLAGS = (RPB_UNDO_FLAGS | RPB_just_deleted);
142142

143143
// List of active blobs controlled by request
144144

145-
typedef Firebird::BePlusTree<ULONG, ULONG, MemoryPool> TempBlobIdTree;
145+
typedef Firebird::BePlusTree<ULONG, ULONG> TempBlobIdTree;
146146

147147
// Affected rows counter class
148148

@@ -315,7 +315,7 @@ class Request : public pool_alloc<type_req>
315315
: statement(aStatement),
316316
req_pool(pool),
317317
req_memory_stats(&aStatement->pool->getStatsGroup()),
318-
req_blobs(req_pool),
318+
req_blobs(*req_pool),
319319
req_stats(*req_pool),
320320
req_base_stats(*req_pool),
321321
req_ext_stmt(NULL),

0 commit comments

Comments
 (0)