Optimize calls to std::string::find() and friends for a single char.

The character literal overload is more efficient.

PiperOrigin-RevId: 348053258
Change-Id: Ida72d7b6d860e1acf9a914e32d31a208cb23728b
This commit is contained in:
Chris Kennelly 2020-12-17 10:57:49 -08:00 committed by TensorFlower Gardener
parent 8684c6b2e9
commit fd0d7123b1
2 changed files with 3 additions and 3 deletions

View File

@ -20,7 +20,7 @@ namespace tensorflow {
namespace grappler {
const NodeScopeAndName ParseNodeScopeAndName(const string& node_name) {
auto pos = node_name.find_last_of("/");
auto pos = node_name.find_last_of('/');
if (pos == string::npos) {
return {"", node_name};
} else {

View File

@ -48,13 +48,13 @@ const char kScopedAllocatorAttrName[] = "_scoped_allocator";
// matches op_name, i.e. it looks from the name like this node is
// of that op type.
bool HasOpName(const string& node_name, const string& op_name) {
size_t begin = node_name.rfind("/");
size_t begin = node_name.rfind('/');
if (begin == string::npos) {
begin = 0;
} else {
++begin;
}
size_t end = node_name.rfind("_");
size_t end = node_name.rfind('_');
if (end != string::npos) {
size_t p = end + 1;
while (p < node_name.size()) {