diff options
author | Rolf Eike Beer <eike@sf-mail.de> | 2020-03-18 21:01:13 (GMT) |
---|---|---|
committer | Rolf Eike Beer <eike@sf-mail.de> | 2020-03-23 18:47:47 (GMT) |
commit | 36bfb80338bdd93dbecb9776ebd8583a68b6c439 (patch) | |
tree | 73fa80d67a893a3d54a732e6e8fce5f746c13f37 /Source/CTest | |
parent | 0415fa3be7b2940c8aebe2c246bd50139b349d26 (diff) | |
download | CMake-36bfb80338bdd93dbecb9776ebd8583a68b6c439.zip CMake-36bfb80338bdd93dbecb9776ebd8583a68b6c439.tar.gz CMake-36bfb80338bdd93dbecb9776ebd8583a68b6c439.tar.bz2 |
PyCoverage: avoid repeated string splitting, especially for uncovered lines
Diffstat (limited to 'Source/CTest')
-rw-r--r-- | Source/CTest/cmCTestCoverageHandler.cxx | 37 |
1 files changed, 17 insertions, 20 deletions
diff --git a/Source/CTest/cmCTestCoverageHandler.cxx b/Source/CTest/cmCTestCoverageHandler.cxx index 2c8f119..4a0ad33 100644 --- a/Source/CTest/cmCTestCoverageHandler.cxx +++ b/Source/CTest/cmCTestCoverageHandler.cxx @@ -1709,29 +1709,26 @@ int cmCTestCoverageHandler::HandleTracePyCoverage( // Read the coverage count from the beginning of the Trace.py output // line - std::string prefix = nl.substr(0, 6); - if (prefix[5] != ' ' && prefix[5] != ':') { - // This is a hack. We should really do something more elaborate - prefix = nl.substr(0, 7); - if (prefix[6] != ' ' && prefix[6] != ':') { - prefix = nl.substr(0, 8); - if (prefix[7] != ' ' && prefix[7] != ':') { - cmCTestLog(this->CTest, ERROR_MESSAGE, - "Currently the limit is maximum coverage of 999999" - << std::endl); - } + std::string::size_type pos; + int cov = 0; + // This is a hack. We should really do something more elaborate + for (pos = 5; pos < 8; pos++) { + if (nl[pos] == ' ') { + // This line does not have ':' so no coverage here. That said, + // Trace.py does not handle not covered lines versus comments etc. + // So, this will be set to 0. + break; + } + if (nl[pos] == ':') { + cov = atoi(nl.substr(0, pos - 1).c_str()); + break; } } - int cov = atoi(prefix.c_str()); - if (prefix[prefix.size() - 1] != ':') { - // This line does not have ':' so no coverage here. That said, - // Trace.py does not handle not covered lines versus comments etc. - // So, this will be set to 0. - cov = 0; + if (pos == 8) { + cmCTestLog(this->CTest, ERROR_MESSAGE, + "Currently the limit is maximum coverage of 999999" + << std::endl); } - cmCTestOptionalLog( - this->CTest, DEBUG, - "Prefix: " << prefix << " cov: " << cov << std::endl, this->Quiet); // Read the line number starting at the 10th character of the gcov // output line long lineIdx = cnt; |