[Strings] Split String Optimizations (#1325)

* Switch the 2 split calls to SplitString

* Nuke duplicate split in favor of SplitString #1263

* Add a test for SplitString

* Optimize SplitString

Benchmarking:
--------------------------------------------------------------
Benchmark                       Time           CPU Iterations
--------------------------------------------------------------
bench_oldsplit               5201 ns       5201 ns     129500
bench_split                  1269 ns       1269 ns     548906

This is splitting a VERY long SpecialAbilities string. This is ~75%
speed up.
This commit is contained in:
Michael Cook (mackal) authored and GitHub committed 2021-04-22 23:36:39 -05:00
1 parent 00fb9bc9f9
commit dba3010c89
5 files changed
+24 -24

No files matched your search

+10
View File
@@ -30,6 +30,7 @@ public:
TEST_ADD(StringUtilTest::EscapeStringTest);
TEST_ADD(StringUtilTest::EscapeStringMemoryTest);
TEST_ADD(StringUtilTest::SearchDeliminatedStringTest);
TEST_ADD(StringUtilTest::SplitStringTest);
}
~StringUtilTest() {
@@ -108,6 +109,15 @@ public:
TEST_ASSERT(search_deliminated_string(h, "bef") == std::string::npos);
TEST_ASSERT(search_deliminated_string(h, "wwi") == std::string::npos);
}
void SplitStringTest() {
std::string s = "123,456,789,";
auto v = SplitString(s, ',');
TEST_ASSERT(v.size() == 3);
TEST_ASSERT(v[0] == "123");
TEST_ASSERT(v[1] == "456");
TEST_ASSERT(v[2] == "789");
}
};
#endif