diff options
Diffstat (limited to 'src/mongo/bson')
-rw-r--r-- | src/mongo/bson/mutable/damage_vector.h | 24 | ||||
-rw-r--r-- | src/mongo/bson/mutable/document.cpp | 5 | ||||
-rw-r--r-- | src/mongo/bson/mutable/mutable_bson_test.cpp | 6 |
3 files changed, 25 insertions, 10 deletions
diff --git a/src/mongo/bson/mutable/damage_vector.h b/src/mongo/bson/mutable/damage_vector.h index 8122a7c5592..29826ee0974 100644 --- a/src/mongo/bson/mutable/damage_vector.h +++ b/src/mongo/bson/mutable/damage_vector.h @@ -35,21 +35,35 @@ namespace mongo { namespace mutablebson { -// A damage event represents a change of size 'size' byte at starting at offset -// 'target_offset' in some target buffer, with the replacement data being 'size' bytes of -// data from the 'source' offset. The base addresses against which these offsets are to be +// A damage event represents a change of size 'targetSize' byte at starting at offset +// 'targetOffset' in some target buffer, with the replacement data being 'sourceSize' bytes of +// data from the 'sourceOffset'. The base addresses against which these offsets are to be // applied are not captured here. struct DamageEvent { typedef uint32_t OffsetSizeType; + DamageEvent() = default; + + DamageEvent(OffsetSizeType srcOffset, size_t srcSize, OffsetSizeType tgtOffset, size_t tgtSize) + : sourceOffset(srcOffset), + sourceSize(srcSize), + targetOffset(tgtOffset), + targetSize(tgtSize) {} + // Offset of source data (in some buffer held elsewhere). OffsetSizeType sourceOffset; + // Size of the data from the source. + // If 'sourceSize' is zero, no new data is inserted and 'targetSize' of bytes are deleted from + // the target. + size_t sourceSize; + // Offset of target data (in some buffer held elsewhere). OffsetSizeType targetOffset; - // Size of the damage region. - size_t size; + // Size of the data to be replaced in the target. + // If 'targetSize' is zero, no bytes from the target are replaced and the new data is inserted. + size_t targetSize; }; typedef std::vector<DamageEvent> DamageVector; diff --git a/src/mongo/bson/mutable/document.cpp b/src/mongo/bson/mutable/document.cpp index b72b9d8f326..56fa36d11f5 100644 --- a/src/mongo/bson/mutable/document.cpp +++ b/src/mongo/bson/mutable/document.cpp @@ -1032,8 +1032,9 @@ public: size_t size) { _damages.push_back(DamageEvent()); _damages.back().targetOffset = targetOffset; + _damages.back().targetSize = size; _damages.back().sourceOffset = sourceOffset; - _damages.back().size = size; + _damages.back().sourceSize = size; if (kDebugBuild && paranoid) { // Force damage events to new addresses to catch invalidation errors. DamageVector new_damages(_damages); @@ -1122,7 +1123,7 @@ private: // creating and destroying a string and its buffer each time. std::string _fieldNameScratch; - // Queue of damage events and status bit for whether in-place updates are possible. + // Queue of damage events and status bit for whether in-place updates are possible. DamageVector _damages; Document::InPlaceMode _inPlaceMode; }; diff --git a/src/mongo/bson/mutable/mutable_bson_test.cpp b/src/mongo/bson/mutable/mutable_bson_test.cpp index 7e215379cb8..95f1919b06c 100644 --- a/src/mongo/bson/mutable/mutable_bson_test.cpp +++ b/src/mongo/bson/mutable/mutable_bson_test.cpp @@ -954,7 +954,7 @@ void apply(mongo::BSONObj* obj, const mmb::DamageVector& damages, const char* so mmb::DamageVector::const_iterator where = damages.begin(); char* const target = const_cast<char*>(obj->objdata()); for (; where != end; ++where) { - std::memcpy(target + where->targetOffset, source + where->sourceOffset, where->size); + std::memcpy(target + where->targetOffset, source + where->sourceOffset, where->sourceSize); } } } // namespace @@ -2871,7 +2871,7 @@ TEST(DocumentInPlace, GettingInPlaceUpdatesWhenDisabledClearsArguments) { ASSERT_FALSE(doc.isInPlaceModeEnabled()); mmb::DamageVector damages; - const mmb::DamageEvent event = {0}; + const mmb::DamageEvent event{}; damages.push_back(event); const char* source = "foo"; ASSERT_FALSE(doc.getInPlaceUpdates(&damages, &source)); @@ -3244,7 +3244,7 @@ TEST(DocumentComparison, SimpleComparisonWithDeserializedElements) { ASSERT_EQUALS(0, doc1Copy.compareWith(doc1, nullptr)); // Perform an operation on 'c' that doesn't change the serialized value, but - // deserializeds the node. + // deserializes the node. mmb::Document doc2(obj.getOwned()); const mmb::Document doc2Copy(obj.getOwned()); mmb::Element c = doc2.root()["c"]; |