diff options
author | Zufu Liu <unknown> | 2025-01-08 09:20:56 +1100 |
---|---|---|
committer | Zufu Liu <unknown> | 2025-01-08 09:20:56 +1100 |
commit | da41b70b18d8e05bc4f5aba19df9aad511fa3d5a (patch) | |
tree | e5a2ed5c8935166f480022b84bc9ba0908e14a13 | |
parent | 8cb01625f379c89cd59b25750570fc190140ee61 (diff) | |
download | scintilla-mirror-da41b70b18d8e05bc4f5aba19df9aad511fa3d5a.tar.gz |
Feature [feature-requests:#1540]. Optimize InsertEmpty to memset equivalent.
Simplify second argument by std::fill -> std::fill_n, std::copy -> std::copy_n.
-rw-r--r-- | src/SplitVector.h | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/src/SplitVector.h b/src/SplitVector.h index 19b854f5a..081c7cbfb 100644 --- a/src/SplitVector.h +++ b/src/SplitVector.h @@ -191,7 +191,7 @@ public: } RoomFor(insertLength); GapTo(position); - std::fill(body.data() + part1Length, body.data() + part1Length + insertLength, v); + std::fill_n(body.data() + part1Length, insertLength, v); lengthBody += insertLength; part1Length += insertLength; gapLength -= insertLength; @@ -210,10 +210,8 @@ public: } RoomFor(insertLength); GapTo(position); - for (ptrdiff_t elem = part1Length; elem < part1Length + insertLength; elem++) { - T emptyOne = {}; - body[elem] = std::move(emptyOne); - } + T *ptr = body.data() + part1Length; + std::uninitialized_value_construct_n(ptr, insertLength); lengthBody += insertLength; part1Length += insertLength; gapLength -= insertLength; @@ -238,7 +236,7 @@ public: } RoomFor(insertLength); GapTo(positionToInsert); - std::copy(s + positionFrom, s + positionFrom + insertLength, body.data() + part1Length); + std::copy_n(s + positionFrom, insertLength, body.data() + part1Length); lengthBody += insertLength; part1Length += insertLength; gapLength -= insertLength; @@ -284,11 +282,11 @@ public: if (range1Length > part1AfterPosition) range1Length = part1AfterPosition; } - std::copy(body.data() + position, body.data() + position + range1Length, buffer); + std::copy_n(body.data() + position, range1Length, buffer); buffer += range1Length; position = position + range1Length + gapLength; const ptrdiff_t range2Length = retrieveLength - range1Length; - std::copy(body.data() + position, body.data() + position + range2Length, buffer); + std::copy_n(body.data() + position, range2Length, buffer); } /// Compact the buffer and return a pointer to the first element. |