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:
committed by
Mathias Agopian
parent
d135108763
commit
2d6b43827e
@@ -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());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user