cpp-btree: Update to match upstream
minor optimization: minimize calls to end() Minor optimization: increase the chances that the compiler will inline calls to end(). Has been observed to make a difference with gcc 4.9.3. Fix build and warnings on MSVC (2017) Uses static_assert, a C++11 feature. Also adds some explicit uses of static_cast in order to suppress warnings about lossy type conversion.
This commit is contained in:
26
src/3rdparty/cpp-btree/btree.h
vendored
26
src/3rdparty/cpp-btree/btree.h
vendored
@@ -510,11 +510,11 @@ class btree_node {
|
||||
|
||||
// Getter for the position of this node in its parent.
|
||||
int position() const { return fields_.position; }
|
||||
void set_position(int v) { fields_.position = v; }
|
||||
void set_position(int v) { fields_.position = static_cast<typename Params::node_count_type>(v); }
|
||||
|
||||
// Getter/setter for the number of values stored in this node.
|
||||
int count() const { return fields_.count; }
|
||||
void set_count(int v) { fields_.count = v; }
|
||||
void set_count(int v) { fields_.count = static_cast<typename Params::node_count_type>(v); }
|
||||
int max_count() const { return fields_.max_count; }
|
||||
|
||||
// Getter for the parent of this node.
|
||||
@@ -561,7 +561,7 @@ class btree_node {
|
||||
void set_child(int i, btree_node *c) {
|
||||
*mutable_child(i) = c;
|
||||
c->fields_.parent = this;
|
||||
c->fields_.position = i;
|
||||
c->fields_.position = static_cast<typename Params::node_count_type>(i);
|
||||
}
|
||||
|
||||
// Returns the position of the first value whose key is not less than k.
|
||||
@@ -674,7 +674,7 @@ class btree_node {
|
||||
btree_node *n = reinterpret_cast<btree_node*>(f);
|
||||
f->leaf = 1;
|
||||
f->position = 0;
|
||||
f->max_count = max_count;
|
||||
f->max_count = static_cast<typename base_fields::field_type>(max_count);
|
||||
f->count = 0;
|
||||
f->parent = parent;
|
||||
#ifdef BTREE_DEBUG
|
||||
@@ -935,10 +935,12 @@ class btree : public Params::key_compare {
|
||||
return const_iterator(leftmost(), 0);
|
||||
}
|
||||
iterator end() {
|
||||
return iterator(rightmost(), rightmost() ? rightmost()->count() : 0);
|
||||
node_type* const right = rightmost();
|
||||
return iterator(right, right ? right->count() : 0);
|
||||
}
|
||||
const_iterator end() const {
|
||||
return const_iterator(rightmost(), rightmost() ? rightmost()->count() : 0);
|
||||
const node_type* const right = rightmost();
|
||||
return const_iterator(right, right ? right->count() : 0);
|
||||
}
|
||||
reverse_iterator rbegin() {
|
||||
return reverse_iterator(end());
|
||||
@@ -1752,7 +1754,8 @@ inline typename btree<P>::iterator
|
||||
btree<P>::insert_unique(iterator position, const value_type &v) {
|
||||
if (!empty()) {
|
||||
const key_type &key = params_type::key(v);
|
||||
if (position == end() || compare_keys(key, position.key())) {
|
||||
const iterator end = this->end();
|
||||
if (position == end || compare_keys(key, position.key())) {
|
||||
iterator prev = position;
|
||||
if (position == begin() || compare_keys((--prev).key(), key)) {
|
||||
// prev.key() < key < position.key()
|
||||
@@ -1761,7 +1764,7 @@ btree<P>::insert_unique(iterator position, const value_type &v) {
|
||||
} else if (compare_keys(position.key(), key)) {
|
||||
iterator next = position;
|
||||
++next;
|
||||
if (next == end() || compare_keys(key, next.key())) {
|
||||
if (next == end || compare_keys(key, next.key())) {
|
||||
// position.key() < key < next.key()
|
||||
return internal_insert(next, v);
|
||||
}
|
||||
@@ -1799,7 +1802,8 @@ typename btree<P>::iterator
|
||||
btree<P>::insert_multi(iterator position, const value_type &v) {
|
||||
if (!empty()) {
|
||||
const key_type &key = params_type::key(v);
|
||||
if (position == end() || !compare_keys(position.key(), key)) {
|
||||
const iterator end = this->end();
|
||||
if (position == end || !compare_keys(position.key(), key)) {
|
||||
iterator prev = position;
|
||||
if (position == begin() || !compare_keys(key, (--prev).key())) {
|
||||
// prev.key() <= key <= position.key()
|
||||
@@ -1808,7 +1812,7 @@ btree<P>::insert_multi(iterator position, const value_type &v) {
|
||||
} else {
|
||||
iterator next = position;
|
||||
++next;
|
||||
if (next == end() || !compare_keys(next.key(), key)) {
|
||||
if (next == end || !compare_keys(next.key(), key)) {
|
||||
// position.key() < key <= next.key()
|
||||
return internal_insert(next, v);
|
||||
}
|
||||
@@ -1833,7 +1837,7 @@ void btree<P>::assign(const self_type &x) {
|
||||
|
||||
// Assignment can avoid key comparisons because we know the order of the
|
||||
// values is the same order we'll store them in.
|
||||
for (const_iterator iter = x.begin(); iter != x.end(); ++iter) {
|
||||
for (const_iterator iter = x.begin(), xend = x.end(); iter != xend; ++iter) {
|
||||
if (empty()) {
|
||||
insert_multi(*iter);
|
||||
} else {
|
||||
|
Reference in New Issue
Block a user