Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace for(auto <var> to for(auto& <var> #760

Merged
merged 4 commits into from
Jul 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/2d/CCActionInterval.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2495,7 +2495,7 @@ bool Animate::initWithAnimation(Animation* animation)

auto& frames = animation->getFrames();

for (auto& frame : frames)
for (auto&& frame : frames)
{
float value = (accumUnitsOfTime * newUnitOfTimeValue) / singleDuration;
accumUnitsOfTime += frame->getDelayUnits();
Expand Down
4 changes: 2 additions & 2 deletions core/2d/CCAnimation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ bool Animation::initWithSpriteFrames(const Vector<SpriteFrame*>& frames,
_delayPerUnit = delay;
_loops = loops;

for (auto& spriteFrame : frames)
for (auto&& spriteFrame : frames)
{
auto animFrame = AnimationFrame::create(spriteFrame, 1, ValueMap());
_frames.pushBack(animFrame);
Expand All @@ -140,7 +140,7 @@ bool Animation::initWithAnimationFrames(const Vector<AnimationFrame*>& arrayOfAn

setFrames(arrayOfAnimationFrames);

for (auto& animFrame : _frames)
for (auto&& animFrame : _frames)
{
_totalDelayUnits += animFrame->getDelayUnits();
}
Expand Down
4 changes: 2 additions & 2 deletions core/2d/CCAnimationCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ void AnimationCache::parseVersion1(const ValueMap& animations)
ssize_t frameNameSize = frameNames.size();
Vector<AnimationFrame*> frames(frameNameSize);

for (auto& frameName : frameNames)
for (auto&& frameName : frameNames)
{
SpriteFrame* spriteFrame = frameCache->getSpriteFrameByName(frameName.asString());

Expand Down Expand Up @@ -170,7 +170,7 @@ void AnimationCache::parseVersion2(const ValueMap& animations)
// Array of AnimationFrames
Vector<AnimationFrame*> array(static_cast<int>(frameArray.size()));

for (auto& obj : frameArray)
for (auto&& obj : frameArray)
{
ValueMap& entry = obj.asValueMap();
std::string spriteFrameName = entry["spriteframe"].asString();
Expand Down
2 changes: 1 addition & 1 deletion core/2d/CCAutoPolygon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@ TrianglesCommand::Triangles AutoPolygon::triangulate(const std::vector<Vec2>& po
}
}
}
for (auto j : p2points)
for (auto&& j : p2points)
{
delete j;
};
Expand Down
2 changes: 1 addition & 1 deletion core/2d/CCCameraBackgroundBrush.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ void CameraBackgroundColorBrush::drawBackground(Camera* camera)

void CameraBackgroundColorBrush::setColor(const Color4F& color)
{
for (auto& vert : _vertices)
for (auto&& vert : _vertices)
{
vert.colors = Color4B(color);
}
Expand Down
2 changes: 1 addition & 1 deletion core/2d/CCClippingNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ void ClippingNode::setProgramStateRecursively(Node* node, backend::ProgramState*

void ClippingNode::restoreAllProgramStates()
{
for (auto item : _originalStencilProgramState)
for (auto&& item : _originalStencilProgramState)
{
auto node = item.first;
auto programState = item.second;
Expand Down
8 changes: 4 additions & 4 deletions core/2d/CCComponentContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ void ComponentContainer::removeAll()
{
if (!_componentMap.empty())
{
for (auto& iter : _componentMap)
for (auto&& iter : _componentMap)
{
iter.second->onRemove();
iter.second->setOwner(nullptr);
Expand All @@ -117,7 +117,7 @@ void ComponentContainer::visit(float delta)
if (!_componentMap.empty())
{
AX_SAFE_RETAIN(_owner);
for (auto& iter : _componentMap)
for (auto&& iter : _componentMap)
{
iter.second->update(delta);
}
Expand All @@ -127,15 +127,15 @@ void ComponentContainer::visit(float delta)

void ComponentContainer::onEnter()
{
for (auto& iter : _componentMap)
for (auto&& iter : _componentMap)
{
iter.second->onEnter();
}
}

void ComponentContainer::onExit()
{
for (auto& iter : _componentMap)
for (auto&& iter : _componentMap)
{
iter.second->onExit();
}
Expand Down
10 changes: 5 additions & 5 deletions core/2d/CCFastTMXLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ FastTMXLayer::~FastTMXLayer()
AX_SAFE_RELEASE(_vertexBuffer);
AX_SAFE_RELEASE(_indexBuffer);

for (auto& e : _customCommands)
for (auto&& e : _customCommands)
{
AX_SAFE_RELEASE(e.second->getPipelineDescriptor().programState);
delete e.second;
Expand Down Expand Up @@ -633,7 +633,7 @@ void FastTMXLayer::updateTotalQuads()
}

int offset = 0;
for (auto& vertexZOffset : _indicesVertexZOffsets)
for (auto&& vertexZOffset : _indicesVertexZOffsets)
{
std::swap(offset, vertexZOffset.second);
offset += vertexZOffset.second;
Expand Down Expand Up @@ -976,7 +976,7 @@ TMXTileAnimManager::TMXTileAnimManager(FastTMXLayer* layer)
_layer = layer;
for (const auto& p : *_layer->getAnimTileCoord())
{
for (auto tilePos : p.second)
for (auto&& tilePos : p.second)
{
_tasks.pushBack(TMXTileAnimTask::create(_layer, _layer->getTileSet()->_animationInfo.at(p.first), tilePos));
}
Expand All @@ -995,7 +995,7 @@ void TMXTileAnimManager::startAll()
if (_started || _tasks.empty())
return;
_started = true;
for (auto& task : _tasks)
for (auto&& task : _tasks)
{
task->start();
}
Expand All @@ -1006,7 +1006,7 @@ void TMXTileAnimManager::stopAll()
if (!_started)
return;
_started = false;
for (auto& task : _tasks)
for (auto&& task : _tasks)
{
task->stop();
}
Expand Down
4 changes: 2 additions & 2 deletions core/2d/CCFastTMXTiledMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ FastTMXLayer* FastTMXTiledMap::getLayer(std::string_view layerName) const
{
AXASSERT(!layerName.empty(), "Invalid layer name!");

for (auto& child : _children)
for (auto&& child : _children)
{
FastTMXLayer* layer = dynamic_cast<FastTMXLayer*>(child);
if (layer)
Expand Down Expand Up @@ -258,7 +258,7 @@ std::string FastTMXTiledMap::getDescription() const

void FastTMXTiledMap::setTileAnimEnabled(bool enabled)
{
for (auto& child : _children)
for (auto&& child : _children)
{
FastTMXLayer* layer = dynamic_cast<FastTMXLayer*>(child);
if (layer)
Expand Down
6 changes: 3 additions & 3 deletions core/2d/CCFontAtlas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ void FontAtlas::reset()

void FontAtlas::releaseTextures()
{
for (auto& item : _atlasTextures)
for (auto&& item : _atlasTextures)
{
item.second->release();
}
Expand Down Expand Up @@ -203,7 +203,7 @@ void FontAtlas::findNewCharacters(const std::u32string& u32Text, std::unordered_
}
else
{
for (auto charCode : u32Text)
for (auto&& charCode : u32Text)
if (_letterDefinitions.find(charCode) == _letterDefinitions.end())
charset.insert(charCode);
}
Expand Down Expand Up @@ -239,7 +239,7 @@ bool FontAtlas::prepareLetterDefinitions(const std::u32string& utf32Text)

int startY = (int)_currentPageOrigY;

for (auto charCode : charCodeSet)
for (auto&& charCode : charCodeSet)
{
auto bitmap = _fontFreeType->getGlyphBitmap(charCode, bitmapWidth, bitmapHeight, tempRect, tempDef.xAdvance);
if (bitmap && bitmapWidth > 0 && bitmapHeight > 0)
Expand Down
2 changes: 1 addition & 1 deletion core/2d/CCFontAtlasCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ bool FontAtlasCache::releaseFontAtlas(FontAtlas* atlas)
{
if (atlas->getReferenceCount() == 1)
{
for (auto& item : _atlasMap)
for (auto&& item : _atlasMap)
{
if (item.second == atlas)
{
Expand Down
10 changes: 5 additions & 5 deletions core/2d/CCLabel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ bool Label::setProgramState(backend::ProgramState* programState, bool needsRetai
if (Node::setProgramState(programState, needsRetain))
{
updateUniformLocations();
for (auto& batch : _batchCommands)
for (auto&& batch : _batchCommands)
{
updateBatchCommand(batch);
}
Expand Down Expand Up @@ -768,7 +768,7 @@ void Label::updateShaderProgram()

updateUniformLocations();

for (auto& batch : _batchCommands)
for (auto&& batch : _batchCommands)
{
updateBatchCommand(batch);
}
Expand Down Expand Up @@ -1983,7 +1983,7 @@ void Label::draw(Renderer* renderer, const Mat4& transform, uint32_t flags)
continue;

auto& batch = _batchCommands[i++];
for (auto command : batch.getCommandArray())
for (auto&& command : batch.getCommandArray())
{
auto* programState = command->getPipelineDescriptor().programState;
Vec4 textColor(_textColorF.r, _textColorF.g, _textColorF.b, _textColorF.a);
Expand All @@ -2003,9 +2003,9 @@ void Label::draw(Renderer* renderer, const Mat4& transform, uint32_t flags)
void Label::updateBlendState()
{
setOpacityModifyRGB(_blendFunc != BlendFunc::ALPHA_NON_PREMULTIPLIED);
for (auto& batch : _batchCommands)
for (auto&& batch : _batchCommands)
{
for (auto command : batch.getCommandArray())
for (auto&& command : batch.getCommandArray())
{
auto& blendDescriptor = command->getPipelineDescriptor().blendDescriptor;
updateBlend(blendDescriptor, _blendFunc);
Expand Down
4 changes: 2 additions & 2 deletions core/2d/CCLabelTextFormatter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ void Label::computeAlignmentOffset()
_linesOffsetX.assign(_numberOfLines, 0);
break;
case axis::TextHAlignment::CENTER:
for (auto lineWidth : _linesWidth)
for (auto&& lineWidth : _linesWidth)
{
_linesOffsetX.push_back((_contentSize.width - lineWidth) / 2.f);
}
break;
case axis::TextHAlignment::RIGHT:
for (auto lineWidth : _linesWidth)
for (auto&& lineWidth : _linesWidth)
{
_linesOffsetX.push_back(_contentSize.width - lineWidth);
}
Expand Down
2 changes: 1 addition & 1 deletion core/2d/CCMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ bool Menu::initWithArray(const Vector<MenuItem*>& arrayOfItems)

int z = 0;

for (auto& item : arrayOfItems)
for (auto&& item : arrayOfItems)
{
this->addChild(item, z);
z++;
Expand Down
2 changes: 1 addition & 1 deletion core/2d/CCNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ Node::~Node()
// `AX_SAFE_RELEASE_NULL(_actionManager)`.
AX_SAFE_RELEASE_NULL(_userObject);

for (auto& child : _children)
for (auto&& child : _children)
{
child->_parent = nullptr;
}
Expand Down
2 changes: 1 addition & 1 deletion core/2d/CCParticleSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1366,7 +1366,7 @@ void ParticleSystem::resetAnimationDescriptors()
void ParticleSystem::setMultiAnimationRandom()
{
_randomAnimations.clear();
for (auto& a : _animations)
for (auto&& a : _animations)
_randomAnimations.push_back(a.first);
}

Expand Down
4 changes: 2 additions & 2 deletions core/2d/CCPlistSpriteSheetLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ void PlistSpriteSheetLoader::addSpriteFramesWithDictionary(ValueMap& dictionary,
auto textureFileName = Director::getInstance()->getTextureCache()->getTextureFilePath(texture);
Image* image = nullptr;
NinePatchImageParser parser;
for (auto& iter : framesDict)
for (auto&& iter : framesDict)
{
auto& frameDict = iter.second.asValueMap();
auto spriteFrameName = iter.first;
Expand Down Expand Up @@ -394,7 +394,7 @@ void PlistSpriteSheetLoader::reloadSpriteFramesWithDictionary(ValueMap& dict,
spriteSheet->format = getFormat();
spriteSheet->path = plist;

for (auto& iter : framesDict)
for (auto&& iter : framesDict)
{
const ValueMap& frameDict = iter.second.asValueMap();
std::string_view spriteFrameName = iter.first;
Expand Down
20 changes: 10 additions & 10 deletions core/2d/CCProtectedNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ Node* ProtectedNode::getProtectedChildByTag(int tag)
{
AXASSERT(tag != Node::INVALID_TAG, "Invalid tag");

for (auto& child : _protectedChildren)
for (auto&& child : _protectedChildren)
{
if (child && child->getTag() == tag)
return child;
Expand Down Expand Up @@ -182,7 +182,7 @@ void ProtectedNode::removeAllProtectedChildren()
void ProtectedNode::removeAllProtectedChildrenWithCleanup(bool cleanup)
{
// not using detachChild improves speed here
for (auto& child : _protectedChildren)
for (auto&& child : _protectedChildren)
{
// IMPORTANT:
// -1st do onExit
Expand Down Expand Up @@ -361,13 +361,13 @@ void ProtectedNode::updateDisplayedOpacity(uint8_t parentOpacity)

if (_cascadeOpacityEnabled)
{
for (auto child : _children)
for (auto&& child : _children)
{
child->updateDisplayedOpacity(_displayedOpacity);
}
}

for (auto child : _protectedChildren)
for (auto&& child : _protectedChildren)
{
child->updateDisplayedOpacity(_displayedOpacity);
}
Expand Down Expand Up @@ -395,11 +395,11 @@ void ProtectedNode::updateDisplayedColor(const Color3B& parentColor)

void ProtectedNode::disableCascadeColor()
{
for (auto child : _children)
for (auto&& child : _children)
{
child->updateDisplayedColor(Color3B::WHITE);
}
for (auto child : _protectedChildren)
for (auto&& child : _protectedChildren)
{
child->updateDisplayedColor(Color3B::WHITE);
}
Expand All @@ -409,12 +409,12 @@ void ProtectedNode::disableCascadeOpacity()
{
_displayedOpacity = _realOpacity;

for (auto child : _children)
for (auto&& child : _children)
{
child->updateDisplayedOpacity(255);
}

for (auto child : _protectedChildren)
for (auto&& child : _protectedChildren)
{
child->updateDisplayedOpacity(255);
}
Expand All @@ -425,7 +425,7 @@ void ProtectedNode::setCameraMask(unsigned short mask, bool applyChildren)
Node::setCameraMask(mask, applyChildren);
if (applyChildren)
{
for (auto& iter : _protectedChildren)
for (auto&& iter : _protectedChildren)
{
iter->setCameraMask(mask);
}
Expand All @@ -435,7 +435,7 @@ void ProtectedNode::setCameraMask(unsigned short mask, bool applyChildren)
void ProtectedNode::setGlobalZOrder(float globalZOrder)
{
Node::setGlobalZOrder(globalZOrder);
for (auto& child : _protectedChildren)
for (auto&& child : _protectedChildren)
child->setGlobalZOrder(globalZOrder);
}

Expand Down
Loading