Improve StaticString hashing

In a lot of case the StaticString hash can be computed a compile time,
so we now take advantage of that.

Removed StaticString(const char*) ctor, and replaced it with a
StaticString::make() method.

Fixed a couple wrong uses of the old StaticString(const char*) ctor.
This commit is contained in:
Mathias Agopian
2018-12-12 13:47:28 -08:00
committed by Mathias Agopian
parent d135108763
commit 2d6b43827e
8 changed files with 76 additions and 31 deletions

View File

@@ -24,3 +24,18 @@ TEST(CString, EmptyString) {
CString emptyString("");
EXPECT_STREQ("", emptyString.c_str_safe());
}
TEST(StaticString, hash) {
StaticString a("Hello World!");
StaticString b = StaticString::make("Hello World!");
StaticString c("Hello World");
StaticString d("Hello World!");
EXPECT_EQ(a.getHash(), b.getHash());
EXPECT_EQ(a.getHash(), d.getHash());
EXPECT_NE(a.getHash(), c.getHash());
EXPECT_NE(b.getHash(), c.getHash());
std::hash<StaticString> ha;
EXPECT_EQ(ha(a), a.getHash());
}