diff options
| author | Martin Hořeňovský | 2019-09-08 14:49:40 +0200 |
|---|---|---|
| committer | Martin Hořeňovský | 2019-09-08 15:58:10 +0200 |
| commit | 7b865daccc7bba2dcc25a4f0b9ea7348b1b4d61f (patch) | |
| tree | d6964f2f65b8fbcd70e8041e16677339f675f261 /projects | |
| parent | 14362533bb50596049f1b46bcc6d333208576a87 (diff) | |
| download | catch3-7b865daccc7bba2dcc25a4f0b9ea7348b1b4d61f.tar.gz | |
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.
Diffstat (limited to 'projects')
6 files changed, 6 insertions, 54 deletions
diff --git a/projects/SelfTest/Baselines/compact.sw.approved.txt b/projects/SelfTest/Baselines/compact.sw.approved.txt index c6a401fc..3e2984f6 100644 --- a/projects/SelfTest/Baselines/compact.sw.approved.txt +++ b/projects/SelfTest/Baselines/compact.sw.approved.txt @@ -1043,8 +1043,6 @@ String.tests.cpp:<line number>: passed: stdStr == "a stringref" for: "a stringre String.tests.cpp:<line number>: passed: stdStr.size() == sr.size() for: 11 == 11 String.tests.cpp:<line number>: passed: stdStr == "a stringref" for: "a stringref" == "a stringref" String.tests.cpp:<line number>: passed: stdStr.size() == sr.size() for: 11 == 11 -String.tests.cpp:<line number>: passed: stdStr == "a stringref" for: "a stringref" == "a stringref" -String.tests.cpp:<line number>: passed: stdStr.size() == sr.size() for: 11 == 11 ToStringChrono.tests.cpp:<line number>: passed: minute == seconds for: 1 m == 60 s ToStringChrono.tests.cpp:<line number>: passed: hour != seconds for: 1 h != 60 s ToStringChrono.tests.cpp:<line number>: passed: micro != milli for: 1 us != 1 ms diff --git a/projects/SelfTest/Baselines/console.std.approved.txt b/projects/SelfTest/Baselines/console.std.approved.txt index 59ea0426..1f30e8f4 100644 --- a/projects/SelfTest/Baselines/console.std.approved.txt +++ b/projects/SelfTest/Baselines/console.std.approved.txt @@ -1381,5 +1381,5 @@ due to unexpected exception with message: =============================================================================== test cases: 300 | 226 passed | 70 failed | 4 failed as expected -assertions: 1559 | 1407 passed | 131 failed | 21 failed as expected +assertions: 1557 | 1405 passed | 131 failed | 21 failed as expected diff --git a/projects/SelfTest/Baselines/console.sw.approved.txt b/projects/SelfTest/Baselines/console.sw.approved.txt index 6ab478be..3bd3a759 100644 --- a/projects/SelfTest/Baselines/console.sw.approved.txt +++ b/projects/SelfTest/Baselines/console.sw.approved.txt @@ -7786,24 +7786,6 @@ with expansion: ------------------------------------------------------------------------------- StringRef to std::string - implicitly constructed -------------------------------------------------------------------------------- -String.tests.cpp:<line number> -............................................................................... - -String.tests.cpp:<line number>: PASSED: - REQUIRE( stdStr == "a stringref" ) -with expansion: - "a stringref" == "a stringref" - -String.tests.cpp:<line number>: PASSED: - REQUIRE( stdStr.size() == sr.size() ) -with expansion: - 11 == 11 - -------------------------------------------------------------------------------- -StringRef - to std::string explicitly constructed ------------------------------------------------------------------------------- String.tests.cpp:<line number> @@ -12462,5 +12444,5 @@ Misc.tests.cpp:<line number>: PASSED: =============================================================================== test cases: 300 | 210 passed | 86 failed | 4 failed as expected -assertions: 1576 | 1407 passed | 148 failed | 21 failed as expected +assertions: 1574 | 1405 passed | 148 failed | 21 failed as expected diff --git a/projects/SelfTest/Baselines/junit.sw.approved.txt b/projects/SelfTest/Baselines/junit.sw.approved.txt index 11930e67..c3cf2d6f 100644 --- a/projects/SelfTest/Baselines/junit.sw.approved.txt +++ b/projects/SelfTest/Baselines/junit.sw.approved.txt @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <testsuitesloose text artifact > - <testsuite name="<exe-name>" errors="17" failures="132" tests="1577" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}"> + <testsuite name="<exe-name>" errors="17" failures="132" tests="1575" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}"> <properties> <property name="filters" value="~[!nonportable]~[!benchmark]~[approvals]"/> <property name="random-seed" value="1"/> @@ -726,7 +726,6 @@ Matchers.tests.cpp:<line number> <testcase classname="<exe-name>.global" name="StringRef/from std::string/implicitly constructed" time="{duration}"/> <testcase classname="<exe-name>.global" name="StringRef/from std::string/explicitly constructed" time="{duration}"/> <testcase classname="<exe-name>.global" name="StringRef/from std::string/assigned" time="{duration}"/> - <testcase classname="<exe-name>.global" name="StringRef/to std::string/implicitly constructed" time="{duration}"/> <testcase classname="<exe-name>.global" name="StringRef/to std::string/explicitly constructed" time="{duration}"/> <testcase classname="<exe-name>.global" name="StringRef/to std::string/assigned" time="{duration}"/> <testcase classname="<exe-name>.global" name="Stringifying std::chrono::duration helpers" time="{duration}"/> diff --git a/projects/SelfTest/Baselines/xml.sw.approved.txt b/projects/SelfTest/Baselines/xml.sw.approved.txt index 939bd6bf..de3b7657 100644 --- a/projects/SelfTest/Baselines/xml.sw.approved.txt +++ b/projects/SelfTest/Baselines/xml.sw.approved.txt @@ -9602,28 +9602,6 @@ Message from section two <OverallResults successes="2" failures="0" expectedFailures="0"/> </Section> <Section name="to std::string" filename="projects/<exe-name>/IntrospectiveTests/String.tests.cpp" > - <Section name="implicitly constructed" filename="projects/<exe-name>/IntrospectiveTests/String.tests.cpp" > - <Expression success="true" type="REQUIRE" filename="projects/<exe-name>/IntrospectiveTests/String.tests.cpp" > - <Original> - stdStr == "a stringref" - </Original> - <Expanded> - "a stringref" == "a stringref" - </Expanded> - </Expression> - <Expression success="true" type="REQUIRE" filename="projects/<exe-name>/IntrospectiveTests/String.tests.cpp" > - <Original> - stdStr.size() == sr.size() - </Original> - <Expanded> - 11 == 11 - </Expanded> - </Expression> - <OverallResults successes="2" failures="0" expectedFailures="0"/> - </Section> - <OverallResults successes="2" failures="0" expectedFailures="0"/> - </Section> - <Section name="to std::string" filename="projects/<exe-name>/IntrospectiveTests/String.tests.cpp" > <Section name="explicitly constructed" filename="projects/<exe-name>/IntrospectiveTests/String.tests.cpp" > <Expression success="true" type="REQUIRE" filename="projects/<exe-name>/IntrospectiveTests/String.tests.cpp" > <Original> @@ -14834,7 +14812,7 @@ loose text artifact </Section> <OverallResult success="true"/> </TestCase> - <OverallResults successes="1407" failures="149" expectedFailures="21"/> + <OverallResults successes="1405" failures="149" expectedFailures="21"/> </Group> - <OverallResults successes="1407" failures="148" expectedFailures="21"/> + <OverallResults successes="1405" failures="148" expectedFailures="21"/> </Catch> diff --git a/projects/SelfTest/IntrospectiveTests/String.tests.cpp b/projects/SelfTest/IntrospectiveTests/String.tests.cpp index 6a888f90..77c16dcb 100644 --- a/projects/SelfTest/IntrospectiveTests/String.tests.cpp +++ b/projects/SelfTest/IntrospectiveTests/String.tests.cpp @@ -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() ); } |