Skip to content

Commit

Permalink
clang-tidy: fix performance-faster-string-find
Browse files Browse the repository at this point in the history
  • Loading branch information
paroj committed Jan 8, 2018
1 parent bd9e9d8 commit c5cae01
Show file tree
Hide file tree
Showing 24 changed files with 48 additions and 48 deletions.
Expand Up @@ -509,9 +509,9 @@ namespace Ogre {
foundEndOfBody = true;

// Remove first and last braces
size_t pos = functionBody.find("{");
size_t pos = functionBody.find('{');
functionBody.erase(pos, 1);
pos = functionBody.rfind("}");
pos = functionBody.rfind('}');
functionBody.erase(pos, 1);
mFunctionCacheMap.insert(FunctionMap::value_type(*functionInvoc, functionBody));
}
Expand Down
2 changes: 1 addition & 1 deletion OgreMain/src/OgreGpuProgram.cpp
Expand Up @@ -238,7 +238,7 @@ namespace Ogre
const String& name = i->first;
const GpuConstantDefinition& def = i->second;
// only consider non-array entries
if (name.find("[") == String::npos)
if (name.find('[') == String::npos)
{
GpuLogicalIndexUseMap::value_type val(def.logicalIndex,
GpuLogicalIndexUse(def.physicalIndex, def.arraySize * def.elementSize, def.variability));
Expand Down
4 changes: 2 additions & 2 deletions OgreMain/src/OgreImage.cpp
Expand Up @@ -297,7 +297,7 @@ namespace Ogre {

String strExt;

size_t pos = strFileName.find_last_of(".");
size_t pos = strFileName.find_last_of('.');
if( pos != String::npos && pos < (strFileName.length() - 1))
{
strExt = strFileName.substr(pos+1);
Expand All @@ -317,7 +317,7 @@ namespace Ogre {
}

String strExt;
size_t pos = filename.find_last_of(".");
size_t pos = filename.find_last_of('.');
if( pos == String::npos )
OGRE_EXCEPT(
Exception::ERR_INVALIDPARAMS,
Expand Down
8 changes: 4 additions & 4 deletions OgreMain/src/OgreMaterialSerializer.cpp
Expand Up @@ -1924,7 +1924,7 @@ namespace

if (start != String::npos)
{
size_t end = dimensions.find_first_of("[", start);
size_t end = dimensions.find_first_of('[', start);

// int1, int2, etc.
if (end != start)
Expand All @@ -1937,10 +1937,10 @@ namespace
// C-style array
while (start != String::npos)
{
end = dimensions.find_first_of("]", start);
end = dimensions.find_first_of(']', start);
dims *= StringConverter::parseInt(
dimensions.substr(start + 1, end - start - 1));
start = dimensions.find_first_of("[", start);
start = dimensions.find_first_of('[', start);
}
}

Expand Down Expand Up @@ -5445,7 +5445,7 @@ namespace Ogre
// Skip any params with array qualifiers
// These are only for convenience of setters, the full array will be
// written using the base, non-array identifier
if (identifier.find("[") != String::npos)
if (identifier.find('[') != String::npos)
{
return;
}
Expand Down
6 changes: 3 additions & 3 deletions OgreMain/src/OgreScriptTranslator.cpp
Expand Up @@ -4568,7 +4568,7 @@ namespace Ogre{

if (start != String::npos)
{
size_t end = declarator.find_first_of("[", start);
size_t end = declarator.find_first_of('[', start);

// int1, int2, etc.
if (end != start)
Expand All @@ -4581,10 +4581,10 @@ namespace Ogre{
// C-style array
while (start != String::npos)
{
end = declarator.find_first_of("]", start);
end = declarator.find_first_of(']', start);
dimensions *= StringConverter::parseInt(
declarator.substr(start + 1, end - start - 1));
start = declarator.find_first_of("[", end);
start = declarator.find_first_of('[', end);
}
}

Expand Down
2 changes: 1 addition & 1 deletion OgreMain/src/OgreString.cpp
Expand Up @@ -374,7 +374,7 @@ namespace Ogre {
void StringUtil::splitBaseFilename(const Ogre::String& fullName,
Ogre::String& outBasename, Ogre::String& outExtention)
{
size_t i = fullName.find_last_of(".");
size_t i = fullName.find_last_of('.');
if (i == Ogre::String::npos)
{
outExtention.clear();
Expand Down
2 changes: 1 addition & 1 deletion OgreMain/src/OgreTexture.cpp
Expand Up @@ -382,7 +382,7 @@ namespace Ogre {
if (mName.empty())
return BLANKSTRING;

String::size_type pos = mName.find_last_of(".");
String::size_type pos = mName.find_last_of('.');
if (pos != String::npos && pos < (mName.length() - 1))
{
String ext = mName.substr(pos+1);
Expand Down
2 changes: 1 addition & 1 deletion OgreMain/src/OgreTextureUnitState.cpp
Expand Up @@ -478,7 +478,7 @@ namespace Ogre {
String ext;
String baseName;

size_t pos = name.find_last_of(".");
size_t pos = name.find_last_of('.');
baseName = name.substr(0, pos);
ext = name.substr(pos);

Expand Down
6 changes: 3 additions & 3 deletions OgreMain/src/OgreZip.cpp
Expand Up @@ -250,7 +250,7 @@ namespace Ogre {
// If pattern contains a directory name, do a full match
bool full_match = (pattern.find ('/') != String::npos) ||
(pattern.find ('\\') != String::npos);
bool wildCard = pattern.find("*") != String::npos;
bool wildCard = pattern.find('*') != String::npos;

FileInfoList::const_iterator i, iend;
iend = mFileList.end();
Expand All @@ -272,7 +272,7 @@ namespace Ogre {
// If pattern contains a directory name, do a full match
bool full_match = (pattern.find ('/') != String::npos) ||
(pattern.find ('\\') != String::npos);
bool wildCard = pattern.find("*") != String::npos;
bool wildCard = pattern.find('*') != String::npos;

FileInfoList::const_iterator i, iend;
iend = mFileList.end();
Expand All @@ -299,7 +299,7 @@ namespace Ogre {
OGRE_LOCK_AUTO_MUTEX;
String cleanName = filename;
#if !OGRE_RESOURCEMANAGER_STRICT
if(filename.rfind("/") != String::npos)
if(filename.rfind('/') != String::npos)
{
StringVector tokens = StringUtil::split(filename, "/");
cleanName = tokens[tokens.size() - 1];
Expand Down
2 changes: 1 addition & 1 deletion PlugIns/BSPSceneManager/src/OgreBspLevel.cpp
Expand Up @@ -880,7 +880,7 @@ namespace Ogre {
{
StringUtil::toLowerCase(line);
// Remove quotes
while( ( pos = line.find("\"",0) ) != String::npos )
while( ( pos = line.find('\"',0) ) != String::npos )
{
line = line.substr(0,pos) + line.substr(pos+1,line.length()-(pos+1));
}
Expand Down
2 changes: 1 addition & 1 deletion PlugIns/BSPSceneManager/src/OgreBspSceneManager.cpp
Expand Up @@ -95,7 +95,7 @@ namespace Ogre {
mLevel.reset();
// Check extension is .bsp
char extension[6];
size_t pos = filename.find_last_of(".");
size_t pos = filename.find_last_of('.');
if( pos == String::npos )
OGRE_EXCEPT(
Exception::ERR_INVALIDPARAMS,
Expand Down
2 changes: 1 addition & 1 deletion PlugIns/BSPSceneManager/src/OgreQuake3Shader.cpp
Expand Up @@ -267,7 +267,7 @@ namespace Ogre {
size_t pos;
String ext, base;

pos = texName.find_last_of(".");
pos = texName.find_last_of('.');
ext = texName.substr(pos, 4);
StringUtil::toLowerCase(ext);
base = texName.substr(0,pos);
Expand Down
2 changes: 1 addition & 1 deletion PlugIns/CgProgramManager/src/OgreCgFxScriptLoader.cpp
Expand Up @@ -3603,7 +3603,7 @@ namespace Ogre {
String theWordLight = "Light";
if (StringUtil::startsWith(uiNameValueAsString, theWordLight, false))
{
size_t firstSpacePos = uiNameValueAsString.find(" ");
size_t firstSpacePos = uiNameValueAsString.find(' ');
if (firstSpacePos > 0)
{
String lightNumberAsString = uiNameValueAsString.substr(theWordLight.size(), firstSpacePos - theWordLight.size());
Expand Down
8 changes: 4 additions & 4 deletions PlugIns/CgProgramManager/src/OgreCgProgram.cpp
Expand Up @@ -1278,7 +1278,7 @@ namespace Ogre {
{
size_t includePos = i;
size_t afterIncludePos = includePos + 8;
size_t newLineBefore = inSource.rfind("\n", includePos);
size_t newLineBefore = inSource.rfind('\n', includePos);

// check we're not in a comment
size_t lineCommentIt = inSource.rfind("//", includePos);
Expand Down Expand Up @@ -1306,14 +1306,14 @@ namespace Ogre {
}

// find following newline (or EOF)
size_t newLineAfter = inSource.find("\n", afterIncludePos);
size_t newLineAfter = inSource.find('\n', afterIncludePos);
// find include file string container
String endDelimeter = "\"";
size_t startIt = inSource.find("\"", afterIncludePos);
size_t startIt = inSource.find('\"', afterIncludePos);
if (startIt == String::npos || startIt > newLineAfter)
{
// try <>
startIt = inSource.find("<", afterIncludePos);
startIt = inSource.find('<', afterIncludePos);
if (startIt == String::npos || startIt > newLineAfter)
{
OGRE_EXCEPT(Exception::ERR_INTERNAL_ERROR,
Expand Down
Expand Up @@ -359,7 +359,7 @@ namespace Ogre {
// ie you can't start updating an array starting at element 1, must always be element 0.

// if the uniform name has a "[" in it then its an array element uniform.
String::size_type arrayStart = paramName.find("[");
String::size_type arrayStart = paramName.find('[');
if (arrayStart != String::npos)
{
// if not the first array element then skip it and continue to the next uniform
Expand Down
12 changes: 6 additions & 6 deletions RenderSystems/GL/src/OgreGLSupport.cpp
Expand Up @@ -42,13 +42,13 @@ namespace Ogre {

String tmpStr = (const char*)pcVer;
LogManager::getSingleton().logMessage("GL_VERSION = " + tmpStr);
mVersion = tmpStr.substr(0, tmpStr.find(" "));
mVersion = tmpStr.substr(0, tmpStr.find(' '));

// Get vendor
const GLubyte* pcVendor = glGetString(GL_VENDOR);
tmpStr = (const char*)pcVendor;
LogManager::getSingleton().logMessage("GL_VENDOR = " + tmpStr);
mVendor = tmpStr.substr(0, tmpStr.find(" "));
mVendor = tmpStr.substr(0, tmpStr.find(' '));

// Get renderer
const GLubyte* pcRenderer = glGetString(GL_RENDERER);
Expand Down Expand Up @@ -78,23 +78,23 @@ namespace Ogre {
if(v == mVersion)
return true;

String::size_type pos = v.find(".");
String::size_type pos = v.find('.');
if(pos == String::npos)
return false;

String::size_type pos1 = v.rfind(".");
String::size_type pos1 = v.rfind('.');
if(pos1 == String::npos)
return false;

first = ::atoi(v.substr(0, pos).c_str());
second = ::atoi(v.substr(pos + 1, pos1 - (pos + 1)).c_str());
third = ::atoi(v.substr(pos1 + 1, v.length()).c_str());

pos = mVersion.find(".");
pos = mVersion.find('.');
if(pos == String::npos)
return false;

pos1 = mVersion.rfind(".");
pos1 = mVersion.rfind('.');
if(pos1 == String::npos)
return false;

Expand Down
4 changes: 2 additions & 2 deletions RenderSystems/GL3Plus/src/GLSL/OgreGLSLProgramManager.cpp
Expand Up @@ -617,7 +617,7 @@ namespace Ogre {
// always be element 0.

// If the uniform name has a "[" in it then its an array element uniform.
String::size_type arrayStart = paramName.find("[");
String::size_type arrayStart = paramName.find('[');
if (arrayStart != String::npos)
{
// if not the first array element then skip it and continue to the next uniform
Expand Down Expand Up @@ -663,7 +663,7 @@ namespace Ogre {
// parameters are processed one by one

// If the uniform name has a "[" in it then its an array element uniform.
String::size_type arrayStart = paramName.find("[");
String::size_type arrayStart = paramName.find('[');
if (arrayStart != String::npos)
{
// if not the first array element then skip it and continue to the next uniform
Expand Down
2 changes: 1 addition & 1 deletion RenderSystems/GL3Plus/src/GLSL/OgreGLSLShader.cpp
Expand Up @@ -141,7 +141,7 @@ namespace Ogre {
if(versionPos != String::npos)
{
shaderVersion = StringConverter::parseInt(mSource.substr(versionPos+9, 3));
belowVersionPos = mSource.find("\n", versionPos) + 1;
belowVersionPos = mSource.find('\n', versionPos) + 1;
}

// OSX driver only supports glsl150+ in core profile
Expand Down
2 changes: 1 addition & 1 deletion RenderSystems/GL3Plus/src/OgreGL3PlusSupport.cpp
Expand Up @@ -44,7 +44,7 @@ namespace Ogre {
const GLubyte* pcVendor = glGetString(GL_VENDOR);
String tmpStr = (const char*)pcVendor;
LogManager::getSingleton().logMessage("GL_VENDOR = " + tmpStr);
mVendor = tmpStr.substr(0, tmpStr.find(" "));
mVendor = tmpStr.substr(0, tmpStr.find(' '));

// Get renderer
const GLubyte* pcRenderer = glGetString(GL_RENDERER);
Expand Down
2 changes: 1 addition & 1 deletion RenderSystems/GLES2/src/GLSLES/src/OgreGLSLESProgram.cpp
Expand Up @@ -152,7 +152,7 @@ namespace Ogre {
{
size_t versionPos = mSource.find("#version");
int shaderVersion = StringConverter::parseInt(mSource.substr(versionPos+9, 3));
size_t belowVersionPos = mSource.find("\n", versionPos) + 1;
size_t belowVersionPos = mSource.find('\n', versionPos) + 1;

if(shaderVersion >= 300) {
// Check that it's missing and that this shader has a main function, ie. not a child shader.
Expand Down
Expand Up @@ -433,7 +433,7 @@ namespace Ogre {
String paramName = String( uniformName );

// If the uniform name has a "[" in it then its an array element uniform.
String::size_type arrayStart = paramName.find("[");
String::size_type arrayStart = paramName.find('[');
if (arrayStart != String::npos)
{
// If not the first array element then skip it and continue to the next uniform
Expand Down
4 changes: 2 additions & 2 deletions RenderSystems/GLES2/src/OgreGLES2Support.cpp
Expand Up @@ -44,7 +44,7 @@ namespace Ogre {
// https://www.khronos.org/opengles/sdk/docs/man/xhtml/glGetString.xml
size_t offset = sizeof("OpenGL ES ") - 1;
if(tmpStr.length() > offset) {
mVersion.fromString(tmpStr.substr(offset, tmpStr.find(" ", offset)));
mVersion.fromString(tmpStr.substr(offset, tmpStr.find(' ', offset)));
}
#else
// GLES3 way, but should work with ES2 as well, so disabled for now
Expand All @@ -59,7 +59,7 @@ namespace Ogre {
const GLubyte* pcVendor = glGetString(GL_VENDOR);
tmpStr = (const char*)pcVendor;
LogManager::getSingleton().logMessage("GL_VENDOR = " + tmpStr);
mVendor = tmpStr.substr(0, tmpStr.find(" "));
mVendor = tmpStr.substr(0, tmpStr.find(' '));

// Get renderer
const GLubyte* pcRenderer = glGetString(GL_RENDERER);
Expand Down
6 changes: 3 additions & 3 deletions RenderSystems/GLSupport/src/GLSL/OgreGLSLProgramCommon.cpp
Expand Up @@ -74,7 +74,7 @@ void GLSLProgramCommon::extractLayoutQualifiers(void)
VertexElementSemantic semantic;
int index = 0;

String::size_type endPos = shaderSource.find(";", currPos);
String::size_type endPos = shaderSource.find(';', currPos);
if (endPos == String::npos)
{
// Problem, missing semicolon, abort.
Expand All @@ -87,8 +87,8 @@ void GLSLProgramCommon::extractLayoutQualifiers(void)
currPos += 6;

// Skip until '='.
String::size_type eqPos = line.find("=");
String::size_type parenPos = line.find(")");
String::size_type eqPos = line.find('=');
String::size_type parenPos = line.find(')');

// Skip past '=' up to a ')' which contains an integer(the position).
// TODO This could be a definition, does the preprocessor do replacement?
Expand Down
Expand Up @@ -252,7 +252,7 @@ namespace Ogre {
String externalName = parts.front();

// Now there should be an opening brace
String::size_type openBracePos = src.find("{", currPos);
String::size_type openBracePos = src.find('{', currPos);
if (openBracePos != String::npos)
{
currPos = openBracePos + 1;
Expand All @@ -265,11 +265,11 @@ namespace Ogre {
}

// First we need to find the internal name for the uniform block
String::size_type endBracePos = src.find("}", currPos);
String::size_type endBracePos = src.find('}', currPos);

// Find terminating semicolon
currPos = endBracePos + 1;
endPos = src.find(";", currPos);
endPos = src.find(';', currPos);
if (endPos == String::npos)
{
// problem, missing semicolon, abort
Expand All @@ -279,7 +279,7 @@ namespace Ogre {
else
{
// find terminating semicolon
endPos = src.find(";", currPos);
endPos = src.find(';', currPos);
if (endPos == String::npos)
{
// problem, missing semicolon, abort
Expand Down

0 comments on commit c5cae01

Please sign in to comment.