mirror of
https://github.com/asmjit/asmjit.git
synced 2025-12-18 13:04:36 +03:00
Removed sentinel from const-pool binary tree (NULL is used instead).
This commit is contained in:
@@ -24,22 +24,18 @@ namespace asmjit {
|
|||||||
// [asmjit::ConstPoolTree - Ops]
|
// [asmjit::ConstPoolTree - Ops]
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
|
|
||||||
const ConstPoolNode ConstPoolTree::_sentinel = { {
|
|
||||||
const_cast<ConstPoolNode*>(&ConstPoolTree::_sentinel),
|
|
||||||
const_cast<ConstPoolNode*>(&ConstPoolTree::_sentinel)
|
|
||||||
}, 0, 0, 0 };
|
|
||||||
|
|
||||||
//! \internal
|
//! \internal
|
||||||
//!
|
//!
|
||||||
//! Remove left horizontal links.
|
//! Remove left horizontal links.
|
||||||
static ASMJIT_INLINE ConstPoolNode* ConstPoolTree_skewNode(ConstPoolNode* node) {
|
static ASMJIT_INLINE ConstPoolNode* ConstPoolTree_skewNode(ConstPoolNode* node) {
|
||||||
if (node->_link[0]->_level == node->_level && node->_level != 0) {
|
ConstPoolNode* link = node->_link[0];
|
||||||
ConstPoolNode *save = node->_link[0];
|
uint32_t level = node->_level;
|
||||||
|
|
||||||
node->_link[0] = save->_link[1];
|
if (level != 0 && link != NULL && link->_level == level) {
|
||||||
save->_link[1] = node;
|
node->_link[0] = link->_link[1];
|
||||||
|
link->_link[1] = node;
|
||||||
|
|
||||||
node = save;
|
node = link;
|
||||||
}
|
}
|
||||||
|
|
||||||
return node;
|
return node;
|
||||||
@@ -49,13 +45,14 @@ static ASMJIT_INLINE ConstPoolNode* ConstPoolTree_skewNode(ConstPoolNode* node)
|
|||||||
//!
|
//!
|
||||||
//! Remove consecutive horizontal links.
|
//! Remove consecutive horizontal links.
|
||||||
static ASMJIT_INLINE ConstPoolNode* ConstPoolTree_splitNode(ConstPoolNode* node) {
|
static ASMJIT_INLINE ConstPoolNode* ConstPoolTree_splitNode(ConstPoolNode* node) {
|
||||||
if (node->_link[1]->_link[1]->_level == node->_level && node->_level != 0) {
|
ConstPoolNode* link = node->_link[1];
|
||||||
ConstPoolNode *save = node->_link[1];
|
uint32_t level = node->_level;
|
||||||
|
|
||||||
node->_link[1] = save->_link[0];
|
if (level != 0 && link != NULL && link->_link[1] != NULL && link->_link[1]->_level == level) {
|
||||||
save->_link[0] = node;
|
node->_link[1] = link->_link[0];
|
||||||
|
link->_link[0] = node;
|
||||||
|
|
||||||
node = save;
|
node = link;
|
||||||
node->_level++;
|
node->_level++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -63,11 +60,10 @@ static ASMJIT_INLINE ConstPoolNode* ConstPoolTree_splitNode(ConstPoolNode* node)
|
|||||||
}
|
}
|
||||||
|
|
||||||
ConstPoolNode* ConstPoolTree::get(const void* data) {
|
ConstPoolNode* ConstPoolTree::get(const void* data) {
|
||||||
ConstPoolNode* sentinel = const_cast<ConstPoolNode*>(&_sentinel);
|
|
||||||
ConstPoolNode* node = _root;
|
ConstPoolNode* node = _root;
|
||||||
size_t dataSize = _dataSize;
|
size_t dataSize = _dataSize;
|
||||||
|
|
||||||
while (node != sentinel) {
|
while (node != NULL) {
|
||||||
int c = ::memcmp(node->getData(), data, dataSize);
|
int c = ::memcmp(node->getData(), data, dataSize);
|
||||||
if (c == 0)
|
if (c == 0)
|
||||||
return node;
|
return node;
|
||||||
@@ -78,11 +74,10 @@ ConstPoolNode* ConstPoolTree::get(const void* data) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ConstPoolTree::put(ConstPoolNode* newNode) {
|
void ConstPoolTree::put(ConstPoolNode* newNode) {
|
||||||
ConstPoolNode* sentinel = const_cast<ConstPoolNode*>(&_sentinel);
|
|
||||||
size_t dataSize = _dataSize;
|
size_t dataSize = _dataSize;
|
||||||
|
|
||||||
_length++;
|
_length++;
|
||||||
if (_root == sentinel) {
|
if (_root == NULL) {
|
||||||
_root = newNode;
|
_root = newNode;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -97,9 +92,12 @@ void ConstPoolTree::put(ConstPoolNode* newNode) {
|
|||||||
for (;;) {
|
for (;;) {
|
||||||
stack[top++] = node;
|
stack[top++] = node;
|
||||||
dir = ::memcmp(node->getData(), newNode->getData(), dataSize) < 0;
|
dir = ::memcmp(node->getData(), newNode->getData(), dataSize) < 0;
|
||||||
if (node->_link[dir] == sentinel)
|
|
||||||
|
ConstPoolNode* link = node->_link[dir];
|
||||||
|
if (link == NULL)
|
||||||
break;
|
break;
|
||||||
node = node->_link[dir];
|
|
||||||
|
node = link;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Link and rebalance.
|
// Link and rebalance.
|
||||||
@@ -109,8 +107,9 @@ void ConstPoolTree::put(ConstPoolNode* newNode) {
|
|||||||
// Which child?
|
// Which child?
|
||||||
node = stack[--top];
|
node = stack[--top];
|
||||||
|
|
||||||
if (top != 0)
|
if (top != 0) {
|
||||||
dir = stack[top - 1]->_link[1] == node;
|
dir = stack[top - 1]->_link[1] == node;
|
||||||
|
}
|
||||||
|
|
||||||
node = ConstPoolTree_skewNode(node);
|
node = ConstPoolTree_skewNode(node);
|
||||||
node = ConstPoolTree_splitNode(node);
|
node = ConstPoolTree_splitNode(node);
|
||||||
|
|||||||
@@ -63,14 +63,12 @@ struct ConstPoolTree {
|
|||||||
kHeightLimit = 64
|
kHeightLimit = 64
|
||||||
};
|
};
|
||||||
|
|
||||||
ASMJIT_API static const ConstPoolNode _sentinel;
|
|
||||||
|
|
||||||
// --------------------------------------------------------------------------
|
// --------------------------------------------------------------------------
|
||||||
// [Construction / Destruction]
|
// [Construction / Destruction]
|
||||||
// --------------------------------------------------------------------------
|
// --------------------------------------------------------------------------
|
||||||
|
|
||||||
ASMJIT_INLINE ConstPoolTree(size_t dataSize = 0) :
|
ASMJIT_INLINE ConstPoolTree(size_t dataSize = 0) :
|
||||||
_root(const_cast<ConstPoolNode*>(&_sentinel)),
|
_root(NULL),
|
||||||
_length(0),
|
_length(0),
|
||||||
_dataSize(dataSize) {}
|
_dataSize(dataSize) {}
|
||||||
ASMJIT_INLINE ~ConstPoolTree() {}
|
ASMJIT_INLINE ~ConstPoolTree() {}
|
||||||
@@ -80,7 +78,7 @@ struct ConstPoolTree {
|
|||||||
// --------------------------------------------------------------------------
|
// --------------------------------------------------------------------------
|
||||||
|
|
||||||
ASMJIT_INLINE void reset() {
|
ASMJIT_INLINE void reset() {
|
||||||
_root = const_cast<ConstPoolNode*>(&_sentinel);
|
_root = NULL;
|
||||||
_length = 0;
|
_length = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -118,9 +116,8 @@ struct ConstPoolTree {
|
|||||||
ConstPoolNode* link;
|
ConstPoolNode* link;
|
||||||
|
|
||||||
ConstPoolNode* stack[kHeightLimit];
|
ConstPoolNode* stack[kHeightLimit];
|
||||||
ConstPoolNode* sentinel = const_cast<ConstPoolNode*>(&_sentinel);
|
|
||||||
|
|
||||||
if (node == sentinel)
|
if (node == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
size_t top = 0;
|
size_t top = 0;
|
||||||
@@ -128,7 +125,7 @@ struct ConstPoolTree {
|
|||||||
for (;;) {
|
for (;;) {
|
||||||
link = node->_link[0];
|
link = node->_link[0];
|
||||||
|
|
||||||
if (link != sentinel) {
|
if (link != NULL) {
|
||||||
ASMJIT_ASSERT(top != kHeightLimit);
|
ASMJIT_ASSERT(top != kHeightLimit);
|
||||||
stack[top++] = node;
|
stack[top++] = node;
|
||||||
continue;
|
continue;
|
||||||
@@ -137,7 +134,7 @@ struct ConstPoolTree {
|
|||||||
visitor.visit(node);
|
visitor.visit(node);
|
||||||
link = node->_link[1];
|
link = node->_link[1];
|
||||||
|
|
||||||
if (link != sentinel) {
|
if (link != NULL) {
|
||||||
node = link;
|
node = link;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -158,8 +155,8 @@ struct ConstPoolTree {
|
|||||||
if (node == NULL)
|
if (node == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
node->_link[0] = const_cast<ConstPoolNode*>(&_sentinel);
|
node->_link[0] = NULL;
|
||||||
node->_link[1] = const_cast<ConstPoolNode*>(&_sentinel);
|
node->_link[1] = NULL;
|
||||||
node->_level = 1;
|
node->_level = 1;
|
||||||
node->_shared = shared;
|
node->_shared = shared;
|
||||||
node->_offset = static_cast<uint32_t>(offset);
|
node->_offset = static_cast<uint32_t>(offset);
|
||||||
|
|||||||
Reference in New Issue
Block a user