Skip to content

Commit

Permalink
Optimize calls to std::string::find() and friends for a single char.
Browse files Browse the repository at this point in the history
The character literal overload is more efficient.

PiperOrigin-RevId: 348508612
Change-Id: I0b7c657b7144545d043090e23cd5f488eb1f974d
  • Loading branch information
ckennelly authored and copybara-github committed Dec 21, 2020
1 parent 9b7676b commit e31c6ec
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions call_graph.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ CallGraph::Vertex CallGraph::kInvalidVertex =
CallGraph::CallGraph() : md_index_(0.0) {}

std::string CallGraph::GetFilename() const {
const std::string::size_type filename_pos = filename_.rfind("/");
const std::string::size_type filename_pos = filename_.rfind('/');
const std::string filename(filename_.substr(
filename_pos != std::string::npos ? filename_pos + 1 : 0));
const std::string::size_type extension_pos = filename.rfind(".");
const std::string::size_type extension_pos = filename.rfind('.');
return filename.substr(
0, extension_pos != std::string::npos ? extension_pos : filename.size());
}
Expand Down

0 comments on commit e31c6ec

Please sign in to comment.