Minor C++11 code cleanup
Used range-based for loop where it was trivial to do so.
This change should be noop in terms of functionality.
Change-Id: I3d692cc2706f35f5b710e7539fa084365cf28af1
Reviewed-on: https://swiftshader-review.googlesource.com/14628
Tested-by: Alexis Hétu <sugoi@google.com>
Reviewed-by: Nicolas Capens <nicolascapens@google.com>
diff --git a/src/OpenGL/libEGL/Display.cpp b/src/OpenGL/libEGL/Display.cpp
index 0ae67bd..9564cd4 100644
--- a/src/OpenGL/libEGL/Display.cpp
+++ b/src/OpenGL/libEGL/Display.cpp
@@ -580,11 +580,11 @@
bool Display::hasExistingWindowSurface(EGLNativeWindowType window)
{
- for(SurfaceSet::iterator surface = mSurfaceSet.begin(); surface != mSurfaceSet.end(); surface++)
+ for(const auto &surface : mSurfaceSet)
{
- if((*surface)->isWindowSurface())
+ if(surface->isWindowSurface())
{
- if((*surface)->getWindowHandle() == window)
+ if(surface->getWindowHandle() == window)
{
return true;
}
diff --git a/src/OpenGL/libGLESv2/Shader.cpp b/src/OpenGL/libGLESv2/Shader.cpp
index 867a304..ffe589e 100644
--- a/src/OpenGL/libGLESv2/Shader.cpp
+++ b/src/OpenGL/libGLESv2/Shader.cpp
@@ -389,15 +389,15 @@
return GL_VERTEX_SHADER;
}
-int VertexShader::getSemanticIndex(const std::string &attributeName)
+int VertexShader::getSemanticIndex(const std::string &attributeName) const
{
if(!attributeName.empty())
{
- for(glsl::ActiveAttributes::iterator attribute = activeAttributes.begin(); attribute != activeAttributes.end(); attribute++)
+ for(const auto &attribute : activeAttributes)
{
- if(attribute->name == attributeName)
+ if(attribute.name == attributeName)
{
- return attribute->registerIndex;
+ return attribute.registerIndex;
}
}
}
diff --git a/src/OpenGL/libGLESv2/Shader.h b/src/OpenGL/libGLESv2/Shader.h
index 0c29e4b..63d50ae 100644
--- a/src/OpenGL/libGLESv2/Shader.h
+++ b/src/OpenGL/libGLESv2/Shader.h
@@ -99,7 +99,7 @@
~VertexShader();
virtual GLenum getType() const;
- int getSemanticIndex(const std::string &attributeName);
+ int getSemanticIndex(const std::string &attributeName) const;
virtual sw::Shader *getShader() const;
virtual sw::VertexShader *getVertexShader() const;
diff --git a/src/Renderer/Renderer.cpp b/src/Renderer/Renderer.cpp
index 43e01bc..c8fc98f 100644
--- a/src/Renderer/Renderer.cpp
+++ b/src/Renderer/Renderer.cpp
@@ -309,13 +309,12 @@
{
draw->queries = new std::list<Query*>();
bool includePrimitivesWrittenQueries = vertexState.transformFeedbackQueryEnabled && vertexState.transformFeedbackEnabled;
- for(std::list<Query*>::iterator query = queries.begin(); query != queries.end(); query++)
+ for(auto &query : queries)
{
- Query* q = *query;
- if(includePrimitivesWrittenQueries || (q->type != Query::TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN))
+ if(includePrimitivesWrittenQueries || (query->type != Query::TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN))
{
- ++q->reference; // Atomic
- draw->queries->push_back(q);
+ ++query->reference; // Atomic
+ draw->queries->push_back(query);
}
}
}
@@ -972,10 +971,8 @@
if(draw.queries)
{
- for(std::list<Query*>::iterator q = draw.queries->begin(); q != draw.queries->end(); q++)
+ for(auto &query : *(draw.queries))
{
- Query *query = *q;
-
switch(query->type)
{
case Query::FRAGMENTS_PASSED:
diff --git a/src/Shader/PixelShader.cpp b/src/Shader/PixelShader.cpp
index b8b320e..26908bc 100644
--- a/src/Shader/PixelShader.cpp
+++ b/src/Shader/PixelShader.cpp
@@ -167,11 +167,11 @@
{
zOverride = false;
- for(unsigned int i = 0; i < instruction.size(); i++)
+ for(const auto &inst : instruction)
{
- if(instruction[i]->opcode == Shader::OPCODE_TEXM3X2DEPTH ||
- instruction[i]->opcode == Shader::OPCODE_TEXDEPTH ||
- instruction[i]->dst.type == Shader::PARAMETER_DEPTHOUT)
+ if(inst->opcode == Shader::OPCODE_TEXM3X2DEPTH ||
+ inst->opcode == Shader::OPCODE_TEXDEPTH ||
+ inst->dst.type == Shader::PARAMETER_DEPTHOUT)
{
zOverride = true;
@@ -184,10 +184,10 @@
{
kill = false;
- for(unsigned int i = 0; i < instruction.size(); i++)
+ for(const auto &inst : instruction)
{
- if(instruction[i]->opcode == Shader::OPCODE_TEXKILL ||
- instruction[i]->opcode == Shader::OPCODE_DISCARD)
+ if(inst->opcode == Shader::OPCODE_TEXKILL ||
+ inst->opcode == Shader::OPCODE_DISCARD)
{
kill = true;
@@ -226,25 +226,25 @@
samplerType[i] = Shader::SAMPLER_UNKNOWN;
}
- for(unsigned int i = 0; i < instruction.size(); i++)
+ for(const auto &inst : instruction)
{
- if(instruction[i]->dst.type == Shader::PARAMETER_SAMPLER)
+ if(inst->dst.type == Shader::PARAMETER_SAMPLER)
{
- int sampler = instruction[i]->dst.index;
+ int sampler = inst->dst.index;
- samplerType[sampler] = instruction[i]->samplerType;
+ samplerType[sampler] = inst->samplerType;
}
}
bool interpolant[MAX_FRAGMENT_INPUTS][4] = {{false}}; // Interpolants in use
- for(unsigned int i = 0; i < instruction.size(); i++)
+ for(const auto &inst : instruction)
{
- if(instruction[i]->dst.type == Shader::PARAMETER_TEXTURE)
+ if(inst->dst.type == Shader::PARAMETER_TEXTURE)
{
- int index = instruction[i]->dst.index + 2;
+ int index = inst->dst.index + 2;
- switch(instruction[i]->opcode)
+ switch(inst->opcode)
{
case Shader::OPCODE_TEX:
case Shader::OPCODE_TEXBEM:
@@ -297,19 +297,19 @@
for(int argument = 0; argument < 4; argument++)
{
- if(instruction[i]->src[argument].type == Shader::PARAMETER_INPUT ||
- instruction[i]->src[argument].type == Shader::PARAMETER_TEXTURE)
+ if(inst->src[argument].type == Shader::PARAMETER_INPUT ||
+ inst->src[argument].type == Shader::PARAMETER_TEXTURE)
{
- int index = instruction[i]->src[argument].index;
- int swizzle = instruction[i]->src[argument].swizzle;
- int mask = instruction[i]->dst.mask;
+ int index = inst->src[argument].index;
+ int swizzle = inst->src[argument].swizzle;
+ int mask = inst->dst.mask;
- if(instruction[i]->src[argument].type == Shader::PARAMETER_TEXTURE)
+ if(inst->src[argument].type == Shader::PARAMETER_TEXTURE)
{
index += 2;
}
- switch(instruction[i]->opcode)
+ switch(inst->opcode)
{
case Shader::OPCODE_TEX:
case Shader::OPCODE_TEXLDD:
@@ -324,14 +324,14 @@
case Shader::OPCODE_TEXGRAD:
case Shader::OPCODE_TEXGRADOFFSET:
{
- int sampler = instruction[i]->src[1].index;
+ int sampler = inst->src[1].index;
switch(samplerType[sampler])
{
case Shader::SAMPLER_UNKNOWN:
if(version == 0x0104)
{
- if((instruction[i]->src[0].swizzle & 0x30) == 0x20) // .xyz
+ if((inst->src[0].swizzle & 0x30) == 0x20) // .xyz
{
interpolant[index][0] = true;
interpolant[index][1] = true;
@@ -370,24 +370,24 @@
ASSERT(false);
}
- if(instruction[i]->bias)
+ if(inst->bias)
{
interpolant[index][3] = true;
}
- if(instruction[i]->project)
+ if(inst->project)
{
interpolant[index][3] = true;
}
- if(version == 0x0104 && instruction[i]->opcode == Shader::OPCODE_TEX)
+ if(version == 0x0104 && inst->opcode == Shader::OPCODE_TEX)
{
- if(instruction[i]->src[0].modifier == Shader::MODIFIER_DZ)
+ if(inst->src[0].modifier == Shader::MODIFIER_DZ)
{
interpolant[index][2] = true;
}
- if(instruction[i]->src[0].modifier == Shader::MODIFIER_DW)
+ if(inst->src[0].modifier == Shader::MODIFIER_DW)
{
interpolant[index][3] = true;
}
@@ -683,25 +683,25 @@
}
else // Shader Model 3.0 input declaration; v# indexable
{
- for(unsigned int i = 0; i < instruction.size(); i++)
+ for(const auto &inst : instruction)
{
- if(instruction[i]->opcode == Shader::OPCODE_DCL)
+ if(inst->opcode == Shader::OPCODE_DCL)
{
- if(instruction[i]->dst.type == Shader::PARAMETER_INPUT)
+ if(inst->dst.type == Shader::PARAMETER_INPUT)
{
- unsigned char usage = instruction[i]->usage;
- unsigned char index = instruction[i]->usageIndex;
- unsigned char mask = instruction[i]->dst.mask;
- unsigned char reg = instruction[i]->dst.index;
+ unsigned char usage = inst->usage;
+ unsigned char index = inst->usageIndex;
+ unsigned char mask = inst->dst.mask;
+ unsigned char reg = inst->dst.index;
if(mask & 0x01) input[reg][0] = Semantic(usage, index);
if(mask & 0x02) input[reg][1] = Semantic(usage, index);
if(mask & 0x04) input[reg][2] = Semantic(usage, index);
if(mask & 0x08) input[reg][3] = Semantic(usage, index);
}
- else if(instruction[i]->dst.type == Shader::PARAMETER_MISCTYPE)
+ else if(inst->dst.type == Shader::PARAMETER_MISCTYPE)
{
- unsigned char index = instruction[i]->dst.index;
+ unsigned char index = inst->dst.index;
if(index == Shader::VPosIndex)
{
@@ -719,14 +719,14 @@
if(version >= 0x0200)
{
- for(unsigned int i = 0; i < instruction.size(); i++)
+ for(const auto &inst : instruction)
{
- if(instruction[i]->opcode == Shader::OPCODE_DCL)
+ if(inst->opcode == Shader::OPCODE_DCL)
{
- bool centroid = instruction[i]->dst.centroid;
- unsigned char reg = instruction[i]->dst.index;
+ bool centroid = inst->dst.centroid;
+ unsigned char reg = inst->dst.index;
- switch(instruction[i]->dst.type)
+ switch(inst->dst.type)
{
case Shader::PARAMETER_INPUT:
input[reg][0].centroid = centroid;
diff --git a/src/Shader/Shader.cpp b/src/Shader/Shader.cpp
index 231e759..34a10f0 100644
--- a/src/Shader/Shader.cpp
+++ b/src/Shader/Shader.cpp
@@ -1136,10 +1136,10 @@
Shader::~Shader()
{
- for(unsigned int i = 0; i < instruction.size(); i++)
+ for(auto &inst : instruction)
{
- delete instruction[i];
- instruction[i] = 0;
+ delete inst;
+ inst = 0;
}
}
@@ -1454,9 +1454,9 @@
std::ofstream file(fullName, std::ofstream::out);
- for(unsigned int i = 0; i < instruction.size(); i++)
+ for(const auto &inst : instruction)
{
- file << instruction[i]->string(shaderType, version) << std::endl;
+ file << inst->string(shaderType, version) << std::endl;
}
}
@@ -1517,11 +1517,11 @@
calledFunctions.clear();
rescan = false;
- for(unsigned int i = 0; i < instruction.size(); i++)
+ for(const auto &inst : instruction)
{
- if(instruction[i]->isCall())
+ if(inst->isCall())
{
- calledFunctions.insert(instruction[i]->dst.label);
+ calledFunctions.insert(inst->dst.label);
}
}
@@ -1594,26 +1594,26 @@
dirtyConstantsI = 0;
dirtyConstantsB = 0;
- for(unsigned int i = 0; i < instruction.size(); i++)
+ for(const auto &inst : instruction)
{
- switch(instruction[i]->opcode)
+ switch(inst->opcode)
{
case OPCODE_DEF:
- if(instruction[i]->dst.index + 1 > dirtyConstantsF)
+ if(inst->dst.index + 1 > dirtyConstantsF)
{
- dirtyConstantsF = instruction[i]->dst.index + 1;
+ dirtyConstantsF = inst->dst.index + 1;
}
break;
case OPCODE_DEFI:
- if(instruction[i]->dst.index + 1 > dirtyConstantsI)
+ if(inst->dst.index + 1 > dirtyConstantsI)
{
- dirtyConstantsI = instruction[i]->dst.index + 1;
+ dirtyConstantsI = inst->dst.index + 1;
}
break;
case OPCODE_DEFB:
- if(instruction[i]->dst.index + 1 > dirtyConstantsB)
+ if(inst->dst.index + 1 > dirtyConstantsB)
{
- dirtyConstantsB = instruction[i]->dst.index + 1;
+ dirtyConstantsB = inst->dst.index + 1;
}
break;
default:
@@ -1631,9 +1631,9 @@
containsDefine = false;
// Determine global presence of branching instructions
- for(unsigned int i = 0; i < instruction.size(); i++)
+ for(const auto &inst : instruction)
{
- switch(instruction[i]->opcode)
+ switch(inst->opcode)
{
case OPCODE_CALLNZ:
case OPCODE_IF:
@@ -1644,22 +1644,22 @@
case OPCODE_BREAKP:
case OPCODE_LEAVE:
case OPCODE_CONTINUE:
- if(instruction[i]->src[0].type != PARAMETER_CONSTBOOL)
+ if(inst->src[0].type != PARAMETER_CONSTBOOL)
{
dynamicBranching = true;
}
- if(instruction[i]->opcode == OPCODE_LEAVE)
+ if(inst->opcode == OPCODE_LEAVE)
{
containsLeave = true;
}
- if(instruction[i]->isBreak())
+ if(inst->isBreak())
{
containsBreak = true;
}
- if(instruction[i]->opcode == OPCODE_CONTINUE)
+ if(inst->opcode == OPCODE_CONTINUE)
{
containsContinue = true;
}
@@ -1794,36 +1794,36 @@
void Shader::markFunctionAnalysis(unsigned int functionLabel, Analysis flag)
{
bool marker = false;
- for(unsigned int i = 0; i < instruction.size(); i++)
+ for(auto &inst : instruction)
{
if(!marker)
{
- if(instruction[i]->opcode == OPCODE_LABEL && instruction[i]->dst.label == functionLabel)
+ if(inst->opcode == OPCODE_LABEL && inst->dst.label == functionLabel)
{
marker = true;
}
}
else
{
- if(instruction[i]->opcode == OPCODE_RET)
+ if(inst->opcode == OPCODE_RET)
{
break;
}
- else if(instruction[i]->isCall())
+ else if(inst->isCall())
{
- markFunctionAnalysis(instruction[i]->dst.label, flag);
+ markFunctionAnalysis(inst->dst.label, flag);
}
- instruction[i]->analysis |= flag;
+ inst->analysis |= flag;
}
}
}
void Shader::analyzeSamplers()
{
- for(unsigned int i = 0; i < instruction.size(); i++)
+ for(const auto &inst : instruction)
{
- switch(instruction[i]->opcode)
+ switch(inst->opcode)
{
case OPCODE_TEX:
case OPCODE_TEXBEM:
@@ -1848,8 +1848,8 @@
case OPCODE_TEXGRAD:
case OPCODE_TEXGRADOFFSET:
{
- Parameter &dst = instruction[i]->dst;
- Parameter &src1 = instruction[i]->src[1];
+ Parameter &dst = inst->dst;
+ Parameter &src1 = inst->src[1];
if(majorVersion >= 2)
{
@@ -1873,13 +1873,13 @@
{
int callSiteIndex[2048] = {0};
- for(unsigned int i = 0; i < instruction.size(); i++)
+ for(auto &inst : instruction)
{
- if(instruction[i]->opcode == OPCODE_CALL || instruction[i]->opcode == OPCODE_CALLNZ)
+ if(inst->opcode == OPCODE_CALL || inst->opcode == OPCODE_CALLNZ)
{
- int label = instruction[i]->dst.label;
+ int label = inst->dst.label;
- instruction[i]->dst.callSite = callSiteIndex[label]++;
+ inst->dst.callSite = callSiteIndex[label]++;
}
}
}
@@ -1890,14 +1890,14 @@
dynamicallyIndexedInput = false;
dynamicallyIndexedOutput = false;
- for(unsigned int i = 0; i < instruction.size(); i++)
+ for(const auto &inst : instruction)
{
- if(instruction[i]->dst.rel.type == PARAMETER_ADDR ||
- instruction[i]->dst.rel.type == PARAMETER_LOOP ||
- instruction[i]->dst.rel.type == PARAMETER_TEMP ||
- instruction[i]->dst.rel.type == PARAMETER_CONST)
+ if(inst->dst.rel.type == PARAMETER_ADDR ||
+ inst->dst.rel.type == PARAMETER_LOOP ||
+ inst->dst.rel.type == PARAMETER_TEMP ||
+ inst->dst.rel.type == PARAMETER_CONST)
{
- switch(instruction[i]->dst.type)
+ switch(inst->dst.type)
{
case PARAMETER_TEMP: dynamicallyIndexedTemporaries = true; break;
case PARAMETER_INPUT: dynamicallyIndexedInput = true; break;
@@ -1908,12 +1908,12 @@
for(int j = 0; j < 3; j++)
{
- if(instruction[i]->src[j].rel.type == PARAMETER_ADDR ||
- instruction[i]->src[j].rel.type == PARAMETER_LOOP ||
- instruction[i]->src[j].rel.type == PARAMETER_TEMP ||
- instruction[i]->src[j].rel.type == PARAMETER_CONST)
+ if(inst->src[j].rel.type == PARAMETER_ADDR ||
+ inst->src[j].rel.type == PARAMETER_LOOP ||
+ inst->src[j].rel.type == PARAMETER_TEMP ||
+ inst->src[j].rel.type == PARAMETER_CONST)
{
- switch(instruction[i]->src[j].type)
+ switch(inst->src[j].type)
{
case PARAMETER_TEMP: dynamicallyIndexedTemporaries = true; break;
case PARAMETER_INPUT: dynamicallyIndexedInput = true; break;
diff --git a/src/Shader/VertexShader.cpp b/src/Shader/VertexShader.cpp
index 260ee4f..ebdfc97 100644
--- a/src/Shader/VertexShader.cpp
+++ b/src/Shader/VertexShader.cpp
@@ -233,9 +233,9 @@
output[Pos][2] = Semantic(Shader::USAGE_POSITION, 0);
output[Pos][3] = Semantic(Shader::USAGE_POSITION, 0);
- for(unsigned int i = 0; i < instruction.size(); i++)
+ for(const auto &inst : instruction)
{
- const DestinationParameter &dst = instruction[i]->dst;
+ const DestinationParameter &dst = inst->dst;
switch(dst.type)
{
@@ -285,15 +285,15 @@
}
else // Shader Model 3.0 input declaration
{
- for(unsigned int i = 0; i < instruction.size(); i++)
+ for(const auto &inst : instruction)
{
- if(instruction[i]->opcode == Shader::OPCODE_DCL &&
- instruction[i]->dst.type == Shader::PARAMETER_OUTPUT)
+ if(inst->opcode == Shader::OPCODE_DCL &&
+ inst->dst.type == Shader::PARAMETER_OUTPUT)
{
- unsigned char usage = instruction[i]->usage;
- unsigned char usageIndex = instruction[i]->usageIndex;
+ unsigned char usage = inst->usage;
+ unsigned char usageIndex = inst->usageIndex;
- const DestinationParameter &dst = instruction[i]->dst;
+ const DestinationParameter &dst = inst->dst;
if(dst.x) output[dst.index][0] = Semantic(usage, usageIndex);
if(dst.y) output[dst.index][1] = Semantic(usage, usageIndex);
@@ -318,11 +318,12 @@
{
textureSampling = false;
- for(unsigned int i = 0; i < instruction.size() && !textureSampling; i++)
+ for(const auto &inst : instruction)
{
- if(instruction[i]->src[1].type == PARAMETER_SAMPLER)
+ if(inst->src[1].type == PARAMETER_SAMPLER)
{
textureSampling = true;
+ break;
}
}
}