Skip to content

Commit 5bc775e

Browse files
committed
Refactorization: avoid string copying in Path::getPathFromFilename()
1 parent d29117c commit 5bc775e

2 files changed

Lines changed: 3 additions & 4 deletions

File tree

cli/cppcheckexecutor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ class CppCheckExecutor : public ErrorLogger {
140140
* If no errors are found, 0 is returned.
141141
*/
142142
int check_internal(CppCheck& cppcheck, int argc, const char* const argv[]);
143+
143144
/**
144145
* Pointer to current settings; set while check() is running.
145146
*/

lib/path.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,14 +109,12 @@ std::string Path::simplifyPath(std::string originalPath)
109109

110110
std::string Path::getPathFromFilename(const std::string &filename)
111111
{
112-
std::string path = "";
113-
114112
std::size_t pos = filename.find_last_of("\\/");
115113

116114
if (pos != std::string::npos)
117-
path = filename.substr(0, 1 + pos);
115+
return filename.substr(0, 1 + pos);
118116

119-
return path;
117+
return "";
120118
}
121119

122120

0 commit comments

Comments
 (0)