mirror of
https://github.com/catchorg/Catch2.git
synced 2025-08-01 21:05:39 +02:00
Make StringRef's operator std::string explicit
This way it is explicit when there is a `StringRef` -> `std::string` conversion and makes it easier to look for allocations that could be avoided. Doing this has already removed one allocation per registered test case, as there was a completely pointless `StringRef` -> `std::string` conversion when parsing tags of a test case.
This commit is contained in:
@@ -142,11 +142,6 @@ TEST_CASE( "StringRef", "[Strings][StringRef]" ) {
|
||||
SECTION( "to std::string" ) {
|
||||
StringRef sr = "a stringref";
|
||||
|
||||
SECTION( "implicitly constructed" ) {
|
||||
std::string stdStr = sr;
|
||||
REQUIRE( stdStr == "a stringref" );
|
||||
REQUIRE( stdStr.size() == sr.size() );
|
||||
}
|
||||
SECTION( "explicitly constructed" ) {
|
||||
std::string stdStr( sr );
|
||||
REQUIRE( stdStr == "a stringref" );
|
||||
@@ -154,7 +149,7 @@ TEST_CASE( "StringRef", "[Strings][StringRef]" ) {
|
||||
}
|
||||
SECTION( "assigned" ) {
|
||||
std::string stdStr;
|
||||
stdStr = sr;
|
||||
stdStr = static_cast<std::string>(sr);
|
||||
REQUIRE( stdStr == "a stringref" );
|
||||
REQUIRE( stdStr.size() == sr.size() );
|
||||
}
|
||||
|
Reference in New Issue
Block a user