Improve string view to reduce string allocation. (#6644)

This commit is contained in:
Jiaming Yuan
2021-01-27 19:08:52 +08:00
committed by GitHub
parent bc08e0c9d1
commit 1b70a323a7
4 changed files with 33 additions and 9 deletions

View File

@@ -1,5 +1,5 @@
/*!
* Copyright (c) by Contributors 2019
* Copyright (c) by Contributors 2019-2021
*/
#include <gtest/gtest.h>
#include <dmlc/filesystem.h>
@@ -574,4 +574,14 @@ TEST(Json, DISABLED_RoundTripExhaustive) {
test(static_cast<uint32_t>(i));
}
}
TEST(StringView, Basic) {
StringView str{"This is a string."};
std::stringstream ss;
ss << str;
std::string res = ss.str();
ASSERT_EQ(str.size(), res.size());
ASSERT_TRUE(std::equal(res.cbegin(), res.cend(), str.cbegin()));
}
} // namespace xgboost