diff --git a/VersionedMap.cpp b/VersionedMap.cpp index cc130d9..125e24c 100644 --- a/VersionedMap.cpp +++ b/VersionedMap.cpp @@ -961,6 +961,8 @@ struct __attribute__((__visibility__("hidden"))) VersionedMap::Impl { remove(iter); insert(keyAfter({m.param1, m.param1Len}, arena), {}, /*endRange*/ true, iter); + } else if (engulfRight) { + insert({m.param1, m.param1Len}, {}, /*endRange*/ false, iter); } else { insert({m.param1, m.param1Len}, {{nullptr, -1}}, /*endRange*/ false, iter); @@ -992,12 +994,15 @@ struct __attribute__((__visibility__("hidden"))) VersionedMap::Impl { } // Check if we can engulf on the right - end.copyTo(copy); - move(copy, latestVersion); - const auto *next = copy.searchPathSize() > 0 - ? mm.base[copy.backNode()].entry - : nullptr; - const bool engulfRight = next && next->clearTo(); + bool engulfRight = false; + if (!foundEnd) { + end.copyTo(copy); + move(copy, latestVersion); + const auto *next = copy.searchPathSize() > 0 + ? mm.base[copy.backNode()].entry + : nullptr; + engulfRight = next && next->clearTo(); + } if (engulfLeft && foundBegin) { remove(begin);