Prevent unnecessary rotations
This commit is contained in:
@@ -690,8 +690,9 @@ struct __attribute__((__visibility__("hidden"))) VersionedMap::Impl {
|
||||
|
||||
template <std::memory_order kOrder, class T>
|
||||
void search(Key key, T root, int64_t version, Finger &finger) const {
|
||||
finger.clear();
|
||||
// Prevent integer promotion etc
|
||||
static_assert(std::is_same_v<T, uint32_t>);
|
||||
finger.clear();
|
||||
if (root == 0) {
|
||||
return;
|
||||
}
|
||||
@@ -746,7 +747,7 @@ struct __attribute__((__visibility__("hidden"))) VersionedMap::Impl {
|
||||
finger.copyTo(copy);
|
||||
move<std::memory_order_relaxed>(copy, latestVersion, true);
|
||||
if (copy.searchPathSize() == 0) {
|
||||
rangeVersion = -1;
|
||||
rangeVersion = -1; // Sentinel for "no mutation ending here"
|
||||
} else {
|
||||
rangeVersion = mm.base[copy.backNode()].entry->rangeVersion;
|
||||
}
|
||||
@@ -757,8 +758,8 @@ struct __attribute__((__visibility__("hidden"))) VersionedMap::Impl {
|
||||
} else {
|
||||
rangeVersion = latestVersion;
|
||||
if (inserted) {
|
||||
val = {nullptr, -1};
|
||||
pointVersion = -1;
|
||||
val = {nullptr, -1}; // Sentinel for "no point mutation here"
|
||||
pointVersion = -1; // Sentinel for "no point mutation here"
|
||||
} else {
|
||||
auto *entry = mm.base[finger.backNode()].entry;
|
||||
val = {entry->getVal(), entry->valLen};
|
||||
@@ -767,8 +768,9 @@ struct __attribute__((__visibility__("hidden"))) VersionedMap::Impl {
|
||||
}
|
||||
|
||||
// Prepare new node
|
||||
uint32_t node =
|
||||
newNode(pointVersion, rangeVersion, key.p, key.len, val->p, val->len);
|
||||
uint32_t node = newNode(
|
||||
pointVersion, rangeVersion, key.p, key.len, val->p, val->len,
|
||||
inserted ? random.next() : mm.base[finger.backNode()].entry->priority);
|
||||
if (!inserted) {
|
||||
auto &n = mm.base[node];
|
||||
n.pointer[0] = child<std::memory_order_relaxed>(finger.backNode(), false,
|
||||
@@ -881,15 +883,16 @@ struct __attribute__((__visibility__("hidden"))) VersionedMap::Impl {
|
||||
}
|
||||
|
||||
uint32_t newNode(int64_t version, int64_t rangeVersion, const uint8_t *key,
|
||||
int keyLen, const uint8_t *val, int valLen) {
|
||||
int keyLen, const uint8_t *val, int valLen,
|
||||
uint32_t priority) {
|
||||
auto result = mm.allocate();
|
||||
auto &node = mm.base[result];
|
||||
node.updateVersion = version;
|
||||
node.pointer[0] = 0;
|
||||
node.pointer[1] = 0;
|
||||
node.updated.store(false, std::memory_order_relaxed);
|
||||
node.entry = Entry::make(version, rangeVersion, key, keyLen, val, valLen,
|
||||
random.next());
|
||||
node.entry =
|
||||
Entry::make(version, rangeVersion, key, keyLen, val, valLen, priority);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user