diff options
| author | Neil <nyamatongwe@gmail.com> | 2019-12-02 08:39:52 +1100 |
|---|---|---|
| committer | Neil <nyamatongwe@gmail.com> | 2019-12-02 08:39:52 +1100 |
| commit | cf150e2082ff95d8da6f8f74e1d15e1b33ab2e19 (patch) | |
| tree | bd1cbe389c47c6e7a6b1663d2be5254e17d5f61b /src | |
| parent | e9f310d4043e58739c9e661159a35847a7ba5df5 (diff) | |
| download | scintilla-mirror-cf150e2082ff95d8da6f8f74e1d15e1b33ab2e19.tar.gz | |
Backport: Add SparseVector::DeleteRange for efficiently removing ranges.
Backport of changeset 7780:88e65c696c40.
Diffstat (limited to 'src')
| -rw-r--r-- | src/SparseVector.h | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/SparseVector.h b/src/SparseVector.h index 86d631c3f..e508f63da 100644 --- a/src/SparseVector.h +++ b/src/SparseVector.h @@ -154,6 +154,43 @@ public: starts->InsertText(partition, -1); Check(); } + void DeleteRange(Sci::Position position, Sci::Position deleteLength) { + // For now, delete elements in range - may want to leave value at start + // or combine onto position. + if (position > Length() || (deleteLength == 0)) { + return; + } + const Sci::Position positionEnd = position + deleteLength; + assert(positionEnd <= Length()); + if (position == 0) { + // Remove all partitions in range, moving values to start + while ((Elements() > 1) && (starts->PositionFromPartition(1) <= deleteLength)) { + starts->RemovePartition(1); + values->Delete(0); + } + starts->InsertText(0, -deleteLength); + if (Length() == 0) { + ClearValue(0); + } + } else { + const Sci::Position partition = starts->PartitionFromPosition(position); + const bool atPartitionStart = position == starts->PositionFromPartition(partition); + const Sci::Position partitionDelete = partition + (atPartitionStart ? 0 : 1); + assert(partitionDelete > 0); + for (;;) { + const Sci::Position positionAtIndex = starts->PositionFromPartition(partitionDelete); + assert(position <= positionAtIndex); + if (positionAtIndex >= positionEnd) { + break; + } + assert(partitionDelete <= Elements()); + starts->RemovePartition(partitionDelete); + values->Delete(partitionDelete); + } + starts->InsertText(partition - (atPartitionStart ? 1 : 0), -deleteLength); + } + Check(); + } Sci::Position IndexAfter(Sci::Position position) const noexcept { assert(position < Length()); if (position < 0) |
