Skip to content

Commit

Permalink
Use const auto & in a few for loops that were not doing it.
Browse files Browse the repository at this point in the history
Could help with compiler optimizations and thus performance.
  • Loading branch information
ruevs committed Sep 20, 2024
1 parent a31a89a commit da2ed88
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/draw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ void GraphicsWindow::Selection::Draw(bool isHovered, Canvas *canvas) {
auto it = std::unique(refs.begin(), refs.end(),
[](Vector a, Vector b) { return a.Equals(b); });
refs.erase(it, refs.end());
for(Vector p : refs) {
for(const Vector &p : refs) {
canvas->DrawLine(topLeft, p, hcsEmphasis);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/export.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1196,7 +1196,7 @@ void SolveSpaceUI::ExportMeshAsVrmlTo(FILE *f, const Platform::Path &filename, S
}

// Output all the vertices.
for(auto sp : spl.l) {
for(const auto &sp : spl.l) {
fprintf(f, " %f %f %f,\n",
sp.p.x / SS.exportScale,
sp.p.y / SS.exportScale,
Expand Down
2 changes: 1 addition & 1 deletion src/file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ void SolveSpaceUI::SaveUsingTable(const Platform::Path &filename, int type) {
[](std::pair<EntityKey, EntityId> &a, std::pair<EntityKey, EntityId> &b) {
return a.second.v < b.second.v;
});
for(auto it : sorted) {
for(const auto &it : sorted) {
fprintf(fh, " %d %08x %d\n",
it.second.v, it.first.input.v, it.first.copyNumber);
}
Expand Down
2 changes: 1 addition & 1 deletion src/graphicswin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@ void GraphicsWindow::LoopOverPoints(const std::vector<Entity *> &entities,
for(Constraint *c : constraints) {
std::vector<Vector> refs;
c->GetReferencePoints(camera, &refs);
for(Vector p : refs) {
for(const Vector &p : refs) {
HandlePointForZoomToFit(p, pmax, pmin, wmin, usePerspective, camera);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/render/render2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ void SurfaceRenderer::OutputInPaintOrder() {
mp.Clear();
}

for(auto eit : edges) {
for(const auto &eit : edges) {
hStroke hcs = eit.first;
const SEdgeList &el = eit.second;

Expand Down
4 changes: 2 additions & 2 deletions src/srf/boolean.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ static void FindVertsOnCurve(List<SInter> *l, const SCurve *curve, SShell *sh) {
Vector amax, amin;
curve->GetAxisAlignedBounding(&amax, &amin);

for(auto sc : sh->curve) {
for(const auto &sc : sh->curve) {
if(!sc.isExact) continue;

Vector cmax, cmin;
Expand Down Expand Up @@ -157,7 +157,7 @@ SCurve SCurve::MakeCopySplitAgainst(SShell *agnstA, SShell *agnstB,
// Now add any vertex that is on this segment
const Vector lineStart = prev.p;
const Vector lineDirection = (p->p).Minus(prev.p);
for(auto vtx : vertpts) {
for(const auto &vtx : vertpts) {
double t = (vtx.p.Minus(lineStart)).DivProjected(lineDirection);
if((0.0 < t) && (t < 1.0)) {
il.Add(&vtx);
Expand Down

0 comments on commit da2ed88

Please sign in to comment.