summaryrefslogtreecommitdiff
path: root/AK/Tests/TestString.cpp
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-03-22 10:12:55 +0100
committerAndreas Kling <kling@serenityos.org>2020-03-22 13:03:43 +0100
commit4f72f6b8866cfa353a29248a4f1ca7c242949231 (patch)
tree3313c96d2a0f0fbec3f12ebd03ce32447416367f /AK/Tests/TestString.cpp
parent0395b25e3fea1ffa8b20d013b2bfd650e64043ed (diff)
downloadserenity-4f72f6b8866cfa353a29248a4f1ca7c242949231.zip
AK: Add FlyString, a simple flyweight string class
FlyString is a flyweight string class that wraps a RefPtr<StringImpl> known to be unique among the set of FlyStrings. The class is very unoptimized at the moment. When to use FlyString: - When you want O(1) string comparison - When you want to deduplicate a lot of identical strings When not to use FlyString: - For strings that don't need either of the above features - For strings that are likely to be unique
Diffstat (limited to 'AK/Tests/TestString.cpp')
-rw-r--r--AK/Tests/TestString.cpp22
1 files changed, 22 insertions, 0 deletions
diff --git a/AK/Tests/TestString.cpp b/AK/Tests/TestString.cpp
index 0ba1d4233d..7377db0acc 100644
--- a/AK/Tests/TestString.cpp
+++ b/AK/Tests/TestString.cpp
@@ -26,7 +26,9 @@
#include <AK/TestSuite.h>
+#include <AK/FlyString.h>
#include <AK/String.h>
+#include <AK/StringBuilder.h>
TEST_CASE(construct_empty)
{
@@ -137,4 +139,24 @@ TEST_CASE(to_uppercase)
EXPECT(String("AbC").to_uppercase() == "ABC");
}
+TEST_CASE(flystring)
+{
+ {
+ FlyString a("foo");
+ FlyString b("foo");
+ EXPECT_EQ(a.impl(), b.impl());
+ }
+
+ {
+ String a = "foo";
+ FlyString b = a;
+ StringBuilder builder;
+ builder.append('f');
+ builder.append("oo");
+ FlyString c = builder.to_string();
+ EXPECT_EQ(a.impl(), b.impl());
+ EXPECT_EQ(a.impl(), c.impl());
+ }
+}
+
TEST_MAIN(String)