Skip to content

Commit 10530b1

Browse files
authored
Replace push_back() vs emplace_back() on axis/tests/cpp-tests and axis/core (#781)
* Replace push_back() vs emplace_back() on axis\tests\cpp-tests\ D:\______\GitHub\aismann\axis\tests\cpp-tests\Classes Replace Vector push_back() vs emplace_back() #762 * Replace push_back() vs emplace_back() on axis\core\ #781 * Update CCConsole.cpp * Update UIWebViewImpl-android.cpp * Update UIWebViewImpl-android.cpp
1 parent 9b7910d commit 10530b1

File tree

90 files changed

+569
-569
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+569
-569
lines changed

core/2d/CCActionCatmullRom.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ void PointArray::setControlPoints(vector<Vec2> controlPoints)
9696

9797
void PointArray::addControlPoint(const Vec2& controlPoint)
9898
{
99-
_controlPoints.push_back(controlPoint);
99+
_controlPoints.emplace_back(controlPoint);
100100
}
101101

102102
void PointArray::insertControlPoint(const Vec2& controlPoint, ssize_t index)
@@ -132,7 +132,7 @@ PointArray* PointArray::reverse() const
132132
newArray.reserve(_controlPoints.size());
133133
for (auto iter = _controlPoints.rbegin(), iterRend = _controlPoints.rend(); iter != iterRend; ++iter)
134134
{
135-
newArray.push_back(*iter);
135+
newArray.emplace_back(*iter);
136136
}
137137
PointArray* config = PointArray::create(0);
138138
config->setControlPoints(std::move(newArray));

core/2d/CCActionInterval.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2499,7 +2499,7 @@ bool Animate::initWithAnimation(Animation* animation)
24992499
{
25002500
float value = (accumUnitsOfTime * newUnitOfTimeValue) / singleDuration;
25012501
accumUnitsOfTime += frame->getDelayUnits();
2502-
_splitTimes->push_back(value);
2502+
_splitTimes->emplace_back(value);
25032503
}
25042504
return true;
25052505
}

core/2d/CCAutoPolygon.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ std::vector<axis::Vec2> AutoPolygon::marchSquare(const Rect& rect, const Vec2& s
355355
// not found, we go up, and add to case9s;
356356
stepx = 0;
357357
stepy = -1;
358-
case9s.push_back(i);
358+
case9s.emplace_back(i);
359359
}
360360
break;
361361
case 6:
@@ -382,7 +382,7 @@ std::vector<axis::Vec2> AutoPolygon::marchSquare(const Rect& rect, const Vec2& s
382382
// not found, we go up, and add to case9s;
383383
stepx = 1;
384384
stepy = 0;
385-
case6s.push_back(i);
385+
case6s.emplace_back(i);
386386
}
387387
break;
388388
default:
@@ -400,7 +400,7 @@ std::vector<axis::Vec2> AutoPolygon::marchSquare(const Rect& rect, const Vec2& s
400400
}
401401
else
402402
{
403-
_points.push_back(Vec2((float)(curx - rect.origin.x) / _scaleFactor,
403+
_points.emplace_back(Vec2((float)(curx - rect.origin.x) / _scaleFactor,
404404
(float)(rect.size.height - cury + rect.origin.y) / _scaleFactor));
405405
}
406406

@@ -471,8 +471,8 @@ std::vector<axis::Vec2> AutoPolygon::rdp(const std::vector<axis::Vec2>& v, float
471471
else
472472
{
473473
std::vector<Vec2> ret;
474-
ret.push_back(v.front());
475-
ret.push_back(v.back());
474+
ret.emplace_back(v.front());
475+
ret.emplace_back(v.back());
476476
return ret;
477477
}
478478
}
@@ -545,11 +545,11 @@ std::vector<Vec2> AutoPolygon::expand(const std::vector<Vec2>& points, const axi
545545
cl.AddPath(p->Contour, ClipperLib::ptSubject, true);
546546
// create the clipping rect
547547
ClipperLib::Path clamp;
548-
clamp.push_back(ClipperLib::IntPoint(0, 0));
549-
clamp.push_back(ClipperLib::IntPoint(static_cast<ClipperLib::cInt>(rect.size.width / _scaleFactor * PRECISION), 0));
550-
clamp.push_back(ClipperLib::IntPoint(static_cast<ClipperLib::cInt>(rect.size.width / _scaleFactor * PRECISION),
548+
clamp.emplace_back(ClipperLib::IntPoint(0, 0));
549+
clamp.emplace_back(ClipperLib::IntPoint(static_cast<ClipperLib::cInt>(rect.size.width / _scaleFactor * PRECISION), 0));
550+
clamp.emplace_back(ClipperLib::IntPoint(static_cast<ClipperLib::cInt>(rect.size.width / _scaleFactor * PRECISION),
551551
static_cast<ClipperLib::cInt>(rect.size.height / _scaleFactor * PRECISION)));
552-
clamp.push_back(
552+
clamp.emplace_back(
553553
ClipperLib::IntPoint(0, static_cast<ClipperLib::cInt>(rect.size.height / _scaleFactor * PRECISION)));
554554
cl.AddPath(clamp, ClipperLib::ptClip, true);
555555
cl.Execute(ClipperLib::ctIntersection, out);
@@ -562,7 +562,7 @@ std::vector<Vec2> AutoPolygon::expand(const std::vector<Vec2>& points, const axi
562562
}
563563
for (const auto& pt : p2->Contour)
564564
{
565-
outPoints.push_back(Vec2(pt.X / PRECISION, pt.Y / PRECISION));
565+
outPoints.emplace_back(Vec2(pt.X / PRECISION, pt.Y / PRECISION));
566566
}
567567
return outPoints;
568568
}
@@ -579,7 +579,7 @@ TrianglesCommand::Triangles AutoPolygon::triangulate(const std::vector<Vec2>& po
579579
for (const auto& pt : points)
580580
{
581581
p2t::Point* p = new p2t::Point(pt.x, pt.y);
582-
p2points.push_back(p);
582+
p2points.emplace_back(p);
583583
}
584584
p2t::CDT cdt(p2points);
585585
cdt.Triangulate();
@@ -612,7 +612,7 @@ TrianglesCommand::Triangles AutoPolygon::triangulate(const std::vector<Vec2>& po
612612
if (found)
613613
{
614614
// if we found the same vertex, don't add to verts, but use the same vertex with indices
615-
indices.push_back(j);
615+
indices.emplace_back(j);
616616
idx++;
617617
}
618618
else
@@ -621,8 +621,8 @@ TrianglesCommand::Triangles AutoPolygon::triangulate(const std::vector<Vec2>& po
621621
auto c4b = Color4B::WHITE;
622622
auto t2f = Tex2F(0, 0); // don't worry about tex coords now, we calculate that later
623623
V3F_C4B_T2F vert = {v3, c4b, t2f};
624-
verts.push_back(vert);
625-
indices.push_back(vdx);
624+
verts.emplace_back(vert);
625+
indices.emplace_back(vdx);
626626
idx++;
627627
vdx++;
628628
}

core/2d/CCCamera.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ void Camera::setScene(Scene* scene)
504504
auto it = std::find(cameras.begin(), cameras.end(), this);
505505
if (it == cameras.end())
506506
{
507-
_scene->_cameras.push_back(this);
507+
_scene->_cameras.emplace_back(this);
508508
// notify scene that the camera order is dirty
509509
_scene->setCameraOrderDirty();
510510
}

core/2d/CCFastTMXLayer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ void FastTMXLayer::setupTiles()
369369
{
370370
if (_tileSet->_animationInfo.find(gid) != _tileSet->_animationInfo.end())
371371
{
372-
_animTileCoord[gid].push_back(Vec2(newX, y));
372+
_animTileCoord[gid].emplace_back(Vec2(newX, y));
373373
}
374374
}
375375
}

core/2d/CCLabelTextFormatter.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,13 @@ void Label::computeAlignmentOffset()
4444
case axis::TextHAlignment::CENTER:
4545
for (auto&& lineWidth : _linesWidth)
4646
{
47-
_linesOffsetX.push_back((_contentSize.width - lineWidth) / 2.f);
47+
_linesOffsetX.emplace_back((_contentSize.width - lineWidth) / 2.f);
4848
}
4949
break;
5050
case axis::TextHAlignment::RIGHT:
5151
for (auto&& lineWidth : _linesWidth)
5252
{
53-
_linesOffsetX.push_back(_contentSize.width - lineWidth);
53+
_linesOffsetX.emplace_back(_contentSize.width - lineWidth);
5454
}
5555
break;
5656
default:
@@ -174,7 +174,7 @@ bool Label::multilineTextWrap(const std::function<int(const std::u32string&, int
174174
char32_t character = _utf32Text[index];
175175
if (character == StringUtils::UnicodeCharacters::NewLine)
176176
{
177-
_linesWidth.push_back(letterRight);
177+
_linesWidth.emplace_back(letterRight);
178178
letterRight = 0.f;
179179
lineIndex++;
180180
nextTokenX = 0.f;
@@ -222,7 +222,7 @@ bool Label::multilineTextWrap(const std::function<int(const std::u32string&, int
222222
letterX + letterDef.width * _bmfontScale > _maxLineWidth && !StringUtils::isUnicodeSpace(character) &&
223223
nextChangeSize)
224224
{
225-
_linesWidth.push_back(letterRight - whitespaceWidth);
225+
_linesWidth.emplace_back(letterRight - whitespaceWidth);
226226
nextWhitespaceWidth = 0.f;
227227
letterRight = 0.f;
228228
lineIndex++;
@@ -282,12 +282,12 @@ bool Label::multilineTextWrap(const std::function<int(const std::u32string&, int
282282

283283
if (_linesWidth.empty())
284284
{
285-
_linesWidth.push_back(letterRight);
285+
_linesWidth.emplace_back(letterRight);
286286
longestLine = letterRight;
287287
}
288288
else
289289
{
290-
_linesWidth.push_back(letterRight - nextWhitespaceWidth);
290+
_linesWidth.emplace_back(letterRight - nextWhitespaceWidth);
291291
for (auto&& lineWidth : _linesWidth)
292292
{
293293
if (longestLine < lineWidth)
@@ -426,7 +426,7 @@ void Label::recordLetterInfo(const axis::Vec2& point, char32_t utf32Char, int le
426426
if (static_cast<std::size_t>(letterIndex) >= _lettersInfo.size())
427427
{
428428
LetterInfo tmpInfo;
429-
_lettersInfo.push_back(tmpInfo);
429+
_lettersInfo.emplace_back(tmpInfo);
430430
}
431431
_lettersInfo[letterIndex].lineIndex = lineIndex;
432432
_lettersInfo[letterIndex].utf32Char = utf32Char;
@@ -441,7 +441,7 @@ void Label::recordPlaceholderInfo(int letterIndex, char32_t utf32Char)
441441
if (static_cast<std::size_t>(letterIndex) >= _lettersInfo.size())
442442
{
443443
LetterInfo tmpInfo;
444-
_lettersInfo.push_back(tmpInfo);
444+
_lettersInfo.emplace_back(tmpInfo);
445445
}
446446
_lettersInfo[letterIndex].utf32Char = utf32Char;
447447
_lettersInfo[letterIndex].valid = false;

core/2d/CCLight.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ void BaseLight::onEnter()
4141
auto& lights = scene->_lights;
4242
auto iter = std::find(lights.begin(), lights.end(), this);
4343
if (iter == lights.end())
44-
lights.push_back(this);
44+
lights.emplace_back(this);
4545
}
4646
Node::onEnter();
4747
}

core/2d/CCMenu.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ void Menu::alignItemsInColumns(int columns, va_list args)
347347
ValueVector rows;
348348
while (columns)
349349
{
350-
rows.push_back(Value(columns));
350+
rows.emplace_back(Value(columns));
351351
columns = va_arg(args, int);
352352
}
353353
alignItemsInColumnsWithArray(rows);
@@ -439,7 +439,7 @@ void Menu::alignItemsInRows(int rows, va_list args)
439439
ValueVector array;
440440
while (rows)
441441
{
442-
array.push_back(Value(rows));
442+
array.emplace_back(Value(rows));
443443
rows = va_arg(args, int);
444444
}
445445
alignItemsInRowsWithArray(array);
@@ -475,8 +475,8 @@ void Menu::alignItemsInRowsWithArray(const ValueVector& columns)
475475

476476
if (rowsOccupied >= columnRows)
477477
{
478-
columnWidths.push_back(columnWidth);
479-
columnHeights.push_back(columnHeight);
478+
columnWidths.emplace_back(columnWidth);
479+
columnHeights.emplace_back(columnHeight);
480480
width += columnWidth + 10;
481481

482482
rowsOccupied = 0;

core/2d/CCParticleSystem.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1367,7 +1367,7 @@ void ParticleSystem::setMultiAnimationRandom()
13671367
{
13681368
_randomAnimations.clear();
13691369
for (auto&& a : _animations)
1370-
_randomAnimations.push_back(a.first);
1370+
_randomAnimations.emplace_back(a.first);
13711371
}
13721372

13731373
void ParticleSystem::setAnimationIndicesAtlas()

core/2d/CCPlistSpriteSheetLoader.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ void PlistSpriteSheetLoader::addSpriteFramesWithDictionary(ValueMap& dictionary,
264264
auto oneAlias = value.asString();
265265
if (std::find(frameAliases.begin(), frameAliases.end(), oneAlias) == frameAliases.end())
266266
{
267-
frameAliases.push_back(std::move(oneAlias));
267+
frameAliases.emplace_back(std::move(oneAlias));
268268
}
269269
else
270270
{
@@ -462,7 +462,7 @@ void PlistSpriteSheetLoader::reloadSpriteFramesWithDictionary(ValueMap& dict,
462462
auto oneAlias = value.asString();
463463
if (std::find(frameAliases.begin(), frameAliases.end(), oneAlias) == frameAliases.end())
464464
{
465-
frameAliases.push_back(std::move(oneAlias));
465+
frameAliases.emplace_back(std::move(oneAlias));
466466
}
467467
else
468468
{

0 commit comments

Comments
 (0)