aboutsummaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
authorNeil <nyamatongwe@gmail.com>2024-02-02 20:52:18 +1100
committerNeil <nyamatongwe@gmail.com>2024-02-02 20:52:18 +1100
commitc57d85c5a8872d192c11f7020ef7c13fbefff206 (patch)
tree55df6b3f7f094fcfbc4115f78f9b507447cc70a1 /test
parent687046150ab6d5fc7b0dce1392e0a60ebb6acb6f (diff)
downloadscintilla-mirror-c57d85c5a8872d192c11f7020ef7c13fbefff206.tar.gz
Implement ScaledVector to store undo positions and lengths using less memory in
most cases. Often reduces memory use by around 50% for 32-bit builds and 75% for 64-bit builds as it may use 2-bytes for a position or length instead of 4 or 8 bytes.
Diffstat (limited to 'test')
-rw-r--r--test/unit/testCellBuffer.cxx50
1 files changed, 50 insertions, 0 deletions
diff --git a/test/unit/testCellBuffer.cxx b/test/unit/testCellBuffer.cxx
index 405bd520d..a0ddceef6 100644
--- a/test/unit/testCellBuffer.cxx
+++ b/test/unit/testCellBuffer.cxx
@@ -266,6 +266,56 @@ void TentativeUndo(UndoHistory &uh) {
uh.TentativeCommit();
}
+TEST_CASE("ScaledVector") {
+
+ ScaledVector sv;
+
+ SECTION("ScalingUp") {
+ sv.ReSize(1);
+ REQUIRE(sv.SizeInBytes() == 1);
+ REQUIRE(sv.ValueAt(0) == 0);
+ sv.SetValueAt(0, 1);
+ REQUIRE(sv.ValueAt(0) == 1);
+ REQUIRE(sv.SignedValueAt(0) == 1);
+ sv.ClearValueAt(0);
+ REQUIRE(sv.ValueAt(0) == 0);
+
+ // Check boundary of 1-byte values
+ sv.SetValueAt(0, 0xff);
+ REQUIRE(sv.ValueAt(0) == 0xff);
+ REQUIRE(sv.SizeInBytes() == 1);
+ // Require expansion to 2 byte elements
+ sv.SetValueAt(0, 0x100);
+ REQUIRE(sv.ValueAt(0) == 0x100);
+ REQUIRE(sv.SizeInBytes() == 2);
+ // Only ever expands, never diminishes element size
+ sv.SetValueAt(0, 0xff);
+ REQUIRE(sv.ValueAt(0) == 0xff);
+ REQUIRE(sv.SizeInBytes() == 2);
+
+ // Check boundary of 2-byte values
+ sv.SetValueAt(0, 0xffff);
+ REQUIRE(sv.ValueAt(0) == 0xffff);
+ REQUIRE(sv.SizeInBytes() == 2);
+ // Require expansion to 2 byte elements
+ sv.SetValueAt(0, 0x10000);
+ REQUIRE(sv.ValueAt(0) == 0x10000);
+ REQUIRE(sv.SizeInBytes() == 3);
+
+ // Check that its not just simple bit patterns that work
+ sv.SetValueAt(0, 0xd4381);
+ REQUIRE(sv.ValueAt(0) == 0xd4381);
+
+ // Add a second item
+ sv.ReSize(2);
+ REQUIRE(sv.SizeInBytes() == 6);
+ // Truncate
+ sv.ReSize(1);
+ REQUIRE(sv.SizeInBytes() == 3);
+ REQUIRE(sv.ValueAt(0) == 0xd4381);
+ }
+}
+
TEST_CASE("UndoHistory") {
UndoHistory uh;