aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/SparseVector.h
diff options
context:
space:
mode:
authorNeil <nyamatongwe@gmail.com>2019-12-01 19:53:48 +1100
committerNeil <nyamatongwe@gmail.com>2019-12-01 19:53:48 +1100
commit7153448eb8dfe267f96eb55aee683172f15cc283 (patch)
tree026adfb64a1529bff16e9c49e1c1510c9184f560 /src/SparseVector.h
parentbce262ab46a8e485febb8e8b6311356ea7571af1 (diff)
downloadscintilla-mirror-7153448eb8dfe267f96eb55aee683172f15cc283.tar.gz
Backport: Fix a bug with deleting the first element in SparseVector that left an extra
empty partition. Add extra checking to Partitioning and turn on checking for UnitTester. Backport of changeset 7777:12fb0335514e.
Diffstat (limited to 'src/SparseVector.h')
-rw-r--r--src/SparseVector.h18
1 files changed, 12 insertions, 6 deletions
diff --git a/src/SparseVector.h b/src/SparseVector.h
index 3b1b7d299..67ad1e1e3 100644
--- a/src/SparseVector.h
+++ b/src/SparseVector.h
@@ -120,6 +120,14 @@ public:
if (startPartition == position) {
if (partition == 0) {
ClearValue(0);
+ if (starts->PositionFromPartition(1) == 1) {
+ // Removing all space of first partition, so remove next partition
+ // and move value if not last
+ if (Elements() > 1) {
+ starts->RemovePartition(partition + 1);
+ values->Delete(partition);
+ }
+ }
} else if (partition == starts->Partitions()) {
// This should not be possible
ClearValue(partition);
@@ -133,14 +141,11 @@ public:
}
}
starts->InsertText(partition, -1);
+ Check();
}
void Check() const {
- if (Length() < 0) {
- throw std::runtime_error("SparseVector: Length can not be negative.");
- }
- if (starts->Partitions() < 1) {
- throw std::runtime_error("SparseVector: Must always have 1 or more partitions.");
- }
+#ifdef CHECK_CORRECTNESS
+ starts->Check();
if (starts->Partitions() != values->Length() - 1) {
throw std::runtime_error("SparseVector: Partitions and values different lengths.");
}
@@ -148,6 +153,7 @@ public:
if (values->ValueAt(values->Length() - 1) != T()) {
throw std::runtime_error("SparseVector: Unused style at end changed.");
}
+#endif
}
};