Fix clang-tidy performance-faster-string-find warnings

This commit is contained in:
Eduardo Almeida
2022-10-06 22:25:16 +00:00
parent c1e7757315
commit afb0f160d4
22 changed files with 71 additions and 71 deletions

View File

@@ -78,8 +78,8 @@ static std::map<uint32_t, uint32_t> ssThreshValue; //!< SlowStart threshold val
static uint32_t
GetNodeIdFromContext (std::string context)
{
std::size_t const n1 = context.find_first_of ("/", 1);
std::size_t const n2 = context.find_first_of ("/", n1 + 1);
std::size_t const n1 = context.find_first_of ('/', 1);
std::size_t const n2 = context.find_first_of ('/', n1 + 1);
return std::stoul (context.substr (n1 + 1, n2 - n1 - 1));
}

View File

@@ -208,8 +208,8 @@ std::string
RawTextConfigLoad::Strip (std::string value)
{
NS_LOG_FUNCTION (this << value);
std::string::size_type start = value.find ("\"");
std::string::size_type end = value.find ("\"", 1);
std::string::size_type start = value.find ('\"');
std::string::size_type end = value.find ('\"', 1);
NS_ABORT_MSG_IF (start != 0, "Ill-formed attribute value: " << value);
NS_ABORT_MSG_IF (end != value.size () - 1, "Ill-formed attribute value: " << value);
return value.substr (start+1, end-start-1);

View File

@@ -234,7 +234,7 @@ CommandLine::HandleOption (const std::string & param) const
}
else
{
cur = arg.find ("-");
cur = arg.find ('-');
if (cur == 0)
{
arg = arg.substr (1, arg.size () - 1);
@@ -246,7 +246,7 @@ CommandLine::HandleOption (const std::string & param) const
}
}
// find any value following '='
cur = arg.find ("=");
cur = arg.find ('=');
std::string name;
std::string value;
if (cur == std::string::npos)

View File

@@ -230,7 +230,7 @@ ArrayMatcher::Matches (std::size_t i) const
return true;
}
std::string::size_type tmp;
tmp = m_element.find ("|");
tmp = m_element.find ('|');
if (tmp != std::string::npos)
{
std::string left = m_element.substr (0, tmp - 0);
@@ -250,9 +250,9 @@ ArrayMatcher::Matches (std::size_t i) const
NS_LOG_DEBUG ("Array " << i << " does not match " << m_element);
return false;
}
std::string::size_type leftBracket = m_element.find ("[");
std::string::size_type rightBracket = m_element.find ("]");
std::string::size_type dash = m_element.find ("-");
std::string::size_type leftBracket = m_element.find ('[');
std::string::size_type rightBracket = m_element.find (']');
std::string::size_type dash = m_element.find ('-');
if (leftBracket == 0 && rightBracket == m_element.size () - 1
&& dash > leftBracket && dash < rightBracket)
{
@@ -380,13 +380,13 @@ Resolver::Canonicalize ()
NS_LOG_FUNCTION (this);
// ensure that we start and end with a '/'
std::string::size_type tmp = m_path.find ("/");
std::string::size_type tmp = m_path.find ('/');
if (tmp != 0)
{
// no slash at start
m_path = "/" + m_path;
}
tmp = m_path.find_last_of ("/");
tmp = m_path.find_last_of ('/');
if (tmp != (m_path.size () - 1))
{
// no slash at end
@@ -428,8 +428,8 @@ void
Resolver::DoResolve (std::string path, Ptr<Object> root)
{
NS_LOG_FUNCTION (this << path << root);
NS_ASSERT ((path.find ("/")) == 0);
std::string::size_type next = path.find ("/", 1);
NS_ASSERT ((path.find ('/')) == 0);
std::string::size_type next = path.find ('/', 1);
if (next == std::string::npos)
{
@@ -496,7 +496,7 @@ Resolver::DoResolve (std::string path, Ptr<Object> root)
{
return;
}
std::string::size_type dollarPos = item.find ("$");
std::string::size_type dollarPos = item.find ('$');
if (dollarPos == 0)
{
// This is a call to GetObject
@@ -586,8 +586,8 @@ Resolver::DoArrayResolve (std::string path, const ObjectPtrContainerValue &conta
{
NS_LOG_FUNCTION (this << path << &container);
NS_ASSERT (path != "");
NS_ASSERT ((path.find ("/")) == 0);
std::string::size_type next = path.find ("/", 1);
NS_ASSERT ((path.find ('/')) == 0);
std::string::size_type next = path.find ('/', 1);
if (next == std::string::npos)
{
return;
@@ -667,7 +667,7 @@ ConfigImpl::ParsePath (std::string path, std::string *root, std::string *leaf) c
{
NS_LOG_FUNCTION (this << path << root << leaf);
std::string::size_type slash = path.find_last_of ("/");
std::string::size_type slash = path.find_last_of ('/');
NS_ASSERT (slash != std::string::npos);
*root = path.substr (0, slash);
*leaf = path.substr (slash + 1, path.size () - (slash + 1));
@@ -716,7 +716,7 @@ ConfigImpl::DisconnectWithoutContext (std::string path, const CallbackBase &cb)
MatchContainer container = LookupMatches (root);
if (container.GetN () == 0)
{
std::size_t lastFwdSlash = root.rfind ("/");
std::size_t lastFwdSlash = root.rfind ('/');
NS_LOG_WARN ("Failed to disconnect " << leaf
<< ", the Requested object name = " << root.substr (lastFwdSlash + 1)
<< " does not exits on path " << root.substr (0, lastFwdSlash));
@@ -745,7 +745,7 @@ ConfigImpl::Disconnect (std::string path, const CallbackBase &cb)
MatchContainer container = LookupMatches (root);
if (container.GetN () == 0)
{
std::size_t lastFwdSlash = root.rfind ("/");
std::size_t lastFwdSlash = root.rfind ('/');
NS_LOG_WARN ("Failed to disconnect " << leaf
<< ", the Requested object name = " << root.substr (lastFwdSlash + 1)
<< " does not exits on path " << root.substr (0, lastFwdSlash));

View File

@@ -79,9 +79,9 @@ GlobalValue::InitializeFromEnv ()
std::string::size_type next = 0;
while (next != std::string::npos)
{
next = env.find (";", cur);
next = env.find (';', cur);
std::string tmp = std::string (env, cur, next - cur);
std::string::size_type equal = tmp.find ("=");
std::string::size_type equal = tmp.find ('=');
if (equal != std::string::npos)
{
std::string name = tmp.substr (0, equal);

View File

@@ -227,10 +227,10 @@ std::istream &operator >> (std::istream &is, int64x64_t &value)
bool negative;
// skip heading spaces
std::string::size_type cur;
cur = str.find_first_not_of (" ");
cur = str.find_first_not_of (' ');
std::string::size_type next;
// first, remove the sign.
next = str.find ("-", cur);
next = str.find ('-', cur);
if (next != std::string::npos)
{
negative = true;
@@ -238,7 +238,7 @@ std::istream &operator >> (std::istream &is, int64x64_t &value)
}
else
{
next = str.find ("+", cur);
next = str.find ('+', cur);
if (next != std::string::npos)
{
next++;
@@ -252,7 +252,7 @@ std::istream &operator >> (std::istream &is, int64x64_t &value)
cur = next;
int64_t hi;
uint64_t lo;
next = str.find (".", cur);
next = str.find ('.', cur);
if (next != std::string::npos)
{
hi = ReadHiDigits (str.substr (cur, next - cur));

View File

@@ -91,7 +91,7 @@ PrintList::PrintList ()
std::string::size_type next = 0;
while (next != std::string::npos)
{
next = env.find_first_of (":", cur);
next = env.find_first_of (':', cur);
std::string tmp = std::string (env, cur, next - cur);
if (tmp == "print-list")
{
@@ -155,9 +155,9 @@ LogComponent::EnvVarCheck ()
std::string::size_type next = 0;
while (next != std::string::npos)
{
next = env.find_first_of (":", cur);
next = env.find_first_of (':', cur);
std::string tmp = std::string (env, cur, next - cur);
std::string::size_type equal = tmp.find ("=");
std::string::size_type equal = tmp.find ('=');
std::string component;
if (equal == std::string::npos)
{
@@ -181,7 +181,7 @@ LogComponent::EnvVarCheck ()
do
{
cur_lev = next_lev + 1;
next_lev = tmp.find ("|", cur_lev);
next_lev = tmp.find ('|', cur_lev);
std::string lev = tmp.substr (cur_lev, next_lev - cur_lev);
if (lev == "error")
{
@@ -539,9 +539,9 @@ static void CheckEnvironmentVariables ()
while (next != std::string::npos)
{
next = env.find_first_of (":", cur);
next = env.find_first_of (':', cur);
std::string tmp = std::string (env, cur, next - cur);
std::string::size_type equal = tmp.find ("=");
std::string::size_type equal = tmp.find ('=');
std::string component;
if (equal == std::string::npos)
{
@@ -568,7 +568,7 @@ static void CheckEnvironmentVariables ()
do
{
cur_lev = next_lev + 1;
next_lev = tmp.find ("|", cur_lev);
next_lev = tmp.find ('|', cur_lev);
std::string lev = tmp.substr (cur_lev, next_lev - cur_lev);
if (lev == "error"
|| lev == "warn"

View File

@@ -338,7 +338,7 @@ NamesPriv::Add (std::string name, Ptr<Object> object)
// This must be a name that has the "/Names" namespace prefix omitted.
// Do some reasonableness checking on the rest of the name.
//
offset = name.find ("/");
offset = name.find ('/');
if (offset == 0)
{
NS_ASSERT_MSG (false, "NamesPriv::Add(): Name begins with '/' but not \"/Names\"");
@@ -355,7 +355,7 @@ NamesPriv::Add (std::string name, Ptr<Object> object)
// separates the path from the final segment had better be there since
// we just made sure that at least the namespace name was there.
//
std::string::size_type i = name.rfind ("/");
std::string::size_type i = name.rfind ('/');
NS_ASSERT_MSG (i != std::string::npos, "NamesPriv::Add(): Internal error. Can't find '/' in name");
//
@@ -448,7 +448,7 @@ NamesPriv::Rename (std::string oldpath, std::string newname)
// This must be a name that has the "/Names" namespace prefix omitted.
// Do some reasonableness checking on the rest of the name.
//
offset = oldpath.find ("/");
offset = oldpath.find ('/');
if (offset == 0)
{
NS_ASSERT_MSG (false, "NamesPriv::Add(): Name begins with '/' but not \"/Names\"");
@@ -465,7 +465,7 @@ NamesPriv::Rename (std::string oldpath, std::string newname)
// separates the path from the final segment (name) had better be there since
// we just made sure that at least the namespace name was there.
//
std::string::size_type i = oldpath.rfind ("/");
std::string::size_type i = oldpath.rfind ('/');
NS_ASSERT_MSG (i != std::string::npos, "NamesPriv::Add(): Internal error. Can't find '/' in name");
//
@@ -633,7 +633,7 @@ NamesPriv::Find (std::string path)
for (;;)
{
NS_LOG_LOGIC ("Looking for the object of name " << remaining);
offset = remaining.find ("/");
offset = remaining.find ('/');
if (offset == std::string::npos)
{
//
@@ -658,7 +658,7 @@ NamesPriv::Find (std::string path)
// There are more slashes so this is an intermediate segment of the
// specified name. We need to "recurse" when we find this segment.
//
offset = remaining.find ("/");
offset = remaining.find ('/');
std::string segment = remaining.substr (0, offset);
std::map<std::string, NameNode *>::iterator i = node->m_nameMap.find (segment);

View File

@@ -64,9 +64,9 @@ EnvDictionary (std::string key)
std::string::size_type next = 0;
while (next != std::string::npos)
{
next = env.find (";", cur);
next = env.find (';', cur);
std::string tmp = std::string (env, cur, next - cur);
std::string::size_type equal = tmp.find ("=");
std::string::size_type equal = tmp.find ('=');
if (equal != std::string::npos)
{
std::string name = tmp.substr (0, equal);

View File

@@ -123,8 +123,8 @@ std::istream & operator >> (std::istream &is, ObjectFactory &factory)
is >> v;
std::string::size_type lbracket;
std::string::size_type rbracket;
lbracket = v.find ("[");
rbracket = v.find ("]");
lbracket = v.find ('[');
rbracket = v.find (']');
if (lbracket == std::string::npos && rbracket == std::string::npos)
{
factory.SetTypeId (v);
@@ -143,7 +143,7 @@ std::istream & operator >> (std::istream &is, ObjectFactory &factory)
cur = 0;
while (cur != parameters.size ())
{
std::string::size_type equal = parameters.find ("=", cur);
std::string::size_type equal = parameters.find ('=', cur);
if (equal == std::string::npos)
{
is.setstate (std::ios_base::failbit);
@@ -160,7 +160,7 @@ std::istream & operator >> (std::istream &is, ObjectFactory &factory)
}
else
{
std::string::size_type next = parameters.find ("|", cur);
std::string::size_type next = parameters.find ('|', cur);
std::string value;
if (next == std::string::npos)
{

View File

@@ -538,8 +538,8 @@ DsrRouting::GetElementsFromContext (std::string context)
size_t pos2;
while (pos1 != context.npos)
{
pos1 = context.find ("/",pos1);
pos2 = context.find ("/",pos1 + 1);
pos1 = context.find ('/',pos1);
pos2 = context.find ('/',pos1 + 1);
elements.push_back (context.substr (pos1 + 1,pos2 - (pos1 + 1)));
pos1 = pos2;
}

View File

@@ -163,7 +163,7 @@ RadioBearerStatsConnector::StoreUeManagerPath (std::string context, uint16_t cel
{
NS_LOG_FUNCTION (this << context << cellId << rnti);
std::string ueManagerPath;
ueManagerPath = context.substr (0, context.rfind ("/")) + "/UeMap/" + std::to_string (rnti);
ueManagerPath = context.substr (0, context.rfind ('/')) + "/UeMap/" + std::to_string (rnti);
NS_LOG_DEBUG ("ueManagerPath = " << ueManagerPath);
CellIdRnti key;
key.cellId = cellId;
@@ -213,7 +213,7 @@ void
RadioBearerStatsConnector::ConnectTracesSrb0 (std::string context, uint64_t imsi, uint16_t cellId, uint16_t rnti)
{
NS_LOG_FUNCTION (this << context << imsi << cellId << rnti);
std::string ueRrcPath = context.substr (0, context.rfind ("/"));
std::string ueRrcPath = context.substr (0, context.rfind ('/'));
NS_LOG_LOGIC ("ueRrcPath = " << ueRrcPath);
CellIdRnti key;
key.cellId = cellId;
@@ -243,7 +243,7 @@ void
RadioBearerStatsConnector::ConnectTracesSrb1 (std::string context, uint64_t imsi, uint16_t cellId, uint16_t rnti)
{
NS_LOG_FUNCTION (this << context << imsi << cellId << rnti);
std::string ueRrcPath = context.substr (0, context.rfind ("/"));
std::string ueRrcPath = context.substr (0, context.rfind ('/'));
NS_LOG_LOGIC ("ueRrcPath = " << ueRrcPath);
CellIdRnti key;
key.cellId = cellId;
@@ -290,7 +290,7 @@ RadioBearerStatsConnector::ConnectTracesDrbEnb (std::string context, uint64_t im
NS_LOG_FUNCTION (this << context << imsi << cellId << rnti << (uint16_t)lcid);
NS_LOG_LOGIC ("expected context should match /NodeList/*/DeviceList/*/LteEnbRrc/");
std::string basePath;
basePath = context.substr (0, context.rfind ("/")) + "/DataRadioBearerMap/" + std::to_string (lcid - 2);
basePath = context.substr (0, context.rfind ('/')) + "/DataRadioBearerMap/" + std::to_string (lcid - 2);
NS_LOG_LOGIC ("basePath = " << basePath);
if (m_rlcStats)
{
@@ -326,7 +326,7 @@ RadioBearerStatsConnector::ConnectTracesDrbUe (std::string context, uint64_t ims
NS_LOG_FUNCTION (this << context << imsi << cellId << rnti << (uint16_t)lcid);
NS_LOG_LOGIC ("expected context should match /NodeList/*/DeviceList/*/LteUeRrc/");
std::string basePath;
basePath = context.substr (0, context.rfind ("/")) + "/DataRadioBearerMap/" + std::to_string (lcid);
basePath = context.substr (0, context.rfind ('/')) + "/DataRadioBearerMap/" + std::to_string (lcid);
NS_LOG_LOGIC ("basePath = " << basePath);
if (m_rlcStats)
{

View File

@@ -629,8 +629,8 @@ HasNodeIdNumber (std::string str)
{
// find brackets
std::string::size_type startNodeId = str.find_first_of ("("); // index of left bracket
std::string::size_type endNodeId = str.find_first_of (")"); // index of right bracket
std::string::size_type startNodeId = str.find_first_of ('('); // index of left bracket
std::string::size_type endNodeId = str.find_first_of (')'); // index of right bracket
// Get de nodeId in a string and in a int value
std::string nodeId; // node id
@@ -644,7 +644,7 @@ HasNodeIdNumber (std::string str)
nodeId = str.substr (startNodeId + 1, endNodeId - (startNodeId + 1)); // set node id
// is number is integer is not negative
if (IsNumber (nodeId) && (nodeId.find_first_of (".") == std::string::npos) && (nodeId[0] != '-'))
if (IsNumber (nodeId) && (nodeId.find_first_of ('.') == std::string::npos) && (nodeId[0] != '-'))
{
return true;
}
@@ -661,8 +661,8 @@ GetNodeIdFromToken (std::string str)
if (HasNodeIdNumber (str))
{
// find brackets
std::string::size_type startNodeId = str.find_first_of ("("); // index of left bracket
std::string::size_type endNodeId = str.find_first_of (")"); // index of right bracket
std::string::size_type startNodeId = str.find_first_of ('('); // index of left bracket
std::string::size_type endNodeId = str.find_first_of (')'); // index of right bracket
return str.substr (startNodeId + 1, endNodeId - (startNodeId + 1)); // set node id
}

View File

@@ -594,8 +594,8 @@ AnimationInterface::GetElementsFromContext (const std::string& context) const
std::size_t pos2;
while (pos1 != context.npos)
{
pos1 = context.find ("/",pos1);
pos2 = context.find ("/",pos1 + 1);
pos1 = context.find ('/',pos1);
pos2 = context.find ('/',pos1 + 1);
elements.push_back (context.substr (pos1 + 1,pos2 - (pos1 + 1)));
pos1 = pos2;
pos2 = context.npos;

View File

@@ -254,8 +254,8 @@ std::istream& operator>> (std::istream& is, Address & address)
is >> v;
std::string::size_type firstDash;
std::string::size_type secondDash;
firstDash = v.find ("-");
secondDash = v.find ("-", firstDash+1);
firstDash = v.find ('-');
secondDash = v.find ('-', firstDash+1);
std::string type = v.substr (0, firstDash-0);
std::string len = v.substr (firstDash+1, secondDash-(firstDash+1));
@@ -268,7 +268,7 @@ std::istream& operator>> (std::istream& is, Address & address)
{
std::string tmp;
std::string::size_type next;
next = v.find (":", col);
next = v.find (':', col);
if (next == std::string::npos)
{
tmp = v.substr (col, v.size ()-col);

View File

@@ -251,7 +251,7 @@ std::istream& operator>> (std::istream& is, Mac16Address & address)
{
std::string tmp;
std::string::size_type next;
next = v.find (":", col);
next = v.find (':', col);
if (next == std::string::npos)
{
tmp = v.substr (col, v.size ()-col);

View File

@@ -289,7 +289,7 @@ std::istream& operator>> (std::istream& is, Mac48Address & address)
{
std::string tmp;
std::string::size_type next;
next = v.find (":", col);
next = v.find (':', col);
if (next == std::string::npos)
{
tmp = v.substr (col, v.size ()-col);

View File

@@ -201,7 +201,7 @@ std::istream& operator>> (std::istream& is, Mac64Address & address)
{
std::string tmp;
std::string::size_type next;
next = v.find (":", col);
next = v.find (':', col);
if (next == std::string::npos)
{
tmp = v.substr (col, v.size ()-col);

View File

@@ -97,10 +97,10 @@ FileHelper::WriteProbe (const std::string &typeId,
std::string lastToken;
// See if the path has any wildcards.
bool pathHasNoWildcards = path.find ("*") == std::string::npos;
bool pathHasNoWildcards = path.find ('*') == std::string::npos;
// Remove the last token from the path.
size_t lastSlash = path.find_last_of ("/");
size_t lastSlash = path.find_last_of ('/');
if (lastSlash == std::string::npos)
{
pathWithoutLastToken = path;

View File

@@ -126,11 +126,11 @@ GnuplotHelper::PlotProbe (const std::string &typeId,
std::string lastToken;
// See if the path has any wildcards.
bool pathHasNoWildcards = path.find ("*") == std::string::npos;
bool pathHasNoWildcards = path.find ('*') == std::string::npos;
// Remove the last token from the path; this should correspond to the
// trace source attribute.
size_t lastSlash = path.find_last_of ("/");
size_t lastSlash = path.find_last_of ('/');
if (lastSlash == std::string::npos)
{
pathWithoutLastToken = path;

View File

@@ -72,7 +72,7 @@ void
DataCollectionObject::SetName (std::string name)
{
NS_LOG_FUNCTION (this << name);
for (size_t pos = name.find (" "); pos != std::string::npos; pos = name.find (" ", pos + 1, 1))
for (size_t pos = name.find (' '); pos != std::string::npos; pos = name.find (" ", pos + 1, 1))
{
name[pos] = '_';
}

View File

@@ -49,7 +49,7 @@ GetWildcardMatches (const std::string &configPath,
{
// Find the non-wildcard token.
tokenStart = asterisk + 1;
asterisk = configPath.find ("*", tokenStart);
asterisk = configPath.find ('*', tokenStart);
// If a wildcard character was found, increment this counter.
if (asterisk != std::string::npos)