mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 00:57:45 +00:00
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
This commit is contained in:
parent
0395b25e3f
commit
4f72f6b886
15 changed files with 236 additions and 32 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue