Skip to content

Commit

Permalink
find(':') is more efficient than find(":")
Browse files Browse the repository at this point in the history
See https://clang.llvm.org/extra/clang-tidy/checks/performance-faster-string-find.html

I'm not sure if the efficiency improvement is compiler-specific.
  • Loading branch information
MichaelChirico authored and jimhester committed Oct 18, 2021
1 parent 02132a0 commit 2f3da48
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/xml2_node.cpp
Expand Up @@ -112,7 +112,7 @@ extern "C" SEXP node_attr(
if (Rf_xlength(nsMap_sxp) == 0) {
string = xmlGetProp(node.checked_get(), asXmlChar(name));
} else {
size_t colon = name.find(":");
size_t colon = name.find(':');
if (colon == std::string::npos) {
// Has namespace spec, but attribute not qualified, so look for attribute
// without namespace
Expand Down Expand Up @@ -346,7 +346,7 @@ extern "C" SEXP node_set_attr(SEXP node_sxp, SEXP name_sxp, SEXP value, SEXP nsM
if (Rf_xlength(nsMap) == 0) {
xmlSetProp(node, asXmlChar(name), asXmlChar(value));
} else {
size_t colon = name.find(":");
size_t colon = name.find(':');
if (colon == std::string::npos) {
// Has namespace spec, but attribute not qualified, so just use that name
xmlSetProp(node, asXmlChar(name), asXmlChar(value));
Expand Down Expand Up @@ -389,7 +389,7 @@ extern "C" SEXP node_remove_attr(SEXP node_sxp, SEXP name_sxp, SEXP nsMap) {
if (Rf_xlength(nsMap) == 0) {
xmlUnsetProp(node, asXmlChar(name));
} else {
size_t colon = name.find(":");
size_t colon = name.find(':');
if (colon == std::string::npos) {
// Has namespace spec, but attribute not qualified, so just use that name
xmlUnsetNsProp(node, NULL, asXmlChar(name));
Expand Down

0 comments on commit 2f3da48

Please sign in to comment.