Skip to content

Commit

Permalink
More range-based loops
Browse files Browse the repository at this point in the history
  • Loading branch information
alkino committed Sep 21, 2023
1 parent 0119b5e commit 608870c
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 30 deletions.
17 changes: 8 additions & 9 deletions src/ivoc/graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1526,18 +1526,17 @@ GLabel* Graph::new_proto_label() const {
}

bool Graph::change_label(GLabel* glab, const char* text, GLabel* gl) {
GlyphIndex i, cnt = line_list_.size();
if (strcmp(glab->text(), text)) {
for (i = 0; i < cnt; ++i) {
if (line_list_[i]->label() == glab) {
if (!line_list_[i]->change_expr(text, &symlist_)) {
for (auto& line: line_list_) {
if (line->label() == glab) {
if (!line->change_expr(text, &symlist_)) {

Check warning on line 1532 in src/ivoc/graph.cpp

View check run for this annotation

Codecov / codecov/patch

src/ivoc/graph.cpp#L1530-L1532

Added lines #L1530 - L1532 were not covered by tests
return false;
}
}
}
glab->text(text);
}
i = glyph_index(glab);
GlyphIndex i = glyph_index(glab);

Check warning on line 1539 in src/ivoc/graph.cpp

View check run for this annotation

Codecov / codecov/patch

src/ivoc/graph.cpp#L1539

Added line #L1539 was not covered by tests
if (glab->fixtype() != gl->fixtype()) {
if (gl->fixed()) {
glab->fixed(gl->scale());
Expand Down Expand Up @@ -1570,8 +1569,8 @@ void Graph::change_line_color(GPolyLine* glin) {
}

GlyphIndex Graph::glyph_index(const Glyph* gl) {
GlyphIndex i, cnt = count();
for (i = 0; i < cnt; ++i) {
GlyphIndex cnt = count();
for (GlyphIndex i = 0; i < cnt; ++i) {
Glyph* g = ((GraphItem*) component(i))->body();
if (g == gl) {
return i;
Expand Down Expand Up @@ -1616,8 +1615,8 @@ void Graph::ascii_save(std::ostream& o) const {
}
if (lcnt) {
o << lcnt << " addvar/addexpr lines:";
for (i = 0; i < lcnt; ++i) {
o << " " << line_list_[i]->name();
for (const auto& line: line_list_) {
o << " " << line->name();

Check warning on line 1619 in src/ivoc/graph.cpp

View check run for this annotation

Codecov / codecov/patch

src/ivoc/graph.cpp#L1618-L1619

Added lines #L1618 - L1619 were not covered by tests
}
o << std::endl;
}
Expand Down
21 changes: 6 additions & 15 deletions src/ivoc/scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -576,18 +576,14 @@ void Scene::draw(Canvas* canvas, const Allocation& a) const {
canvas->pop_transform();
}
}
GlyphIndex count = info_->size();
bool are_fixed = false;
for (GlyphIndex index = 0; index < count; ++index) {
SceneInfo& info = (*info_)[index];
for (auto& info: *info_) {
if (info.status_ & SceneInfoFixed) {
are_fixed = true;
} else if (info.glyph_ != NULL && (info.status_ & SceneInfoShowing)) {
Allocation& a = info.allocation_;
Extension b;
b.set(canvas, a);
// printf("%d alloc %g %g %g %g\n", index, a.left(), a.bottom(), a.right(), a.top());
// printf("%d exten %g %g %g %g\n", index, b.left(), b.bottom(), b.right(), b.top());
if (canvas->damaged(b)) {
info.glyph_->draw(canvas, a);
}
Expand All @@ -602,8 +598,7 @@ void Scene::draw(Canvas* canvas, const Allocation& a) const {
const Transformer& tv = XYView::current_draw_view()->s2o();
canvas->transform(tv);
IfIdraw(pict(tv));
for (GlyphIndex index = 0; index < count; ++index) {
SceneInfo& info = (*info_)[index];
for (auto& info: *info_) {
if ((info.status_ & SceneInfoFixed) && info.glyph_ != NULL &&
(info.status_ & SceneInfoShowing)) {
Allocation a = info.allocation_;
Expand Down Expand Up @@ -635,10 +630,8 @@ void Scene::print(Printer* canvas, const Allocation& a) const {
if (background_ != NULL) {
background_->print(canvas, a);
}
GlyphIndex count = info_->size();
bool are_fixed = false;
for (GlyphIndex index = 0; index < count; ++index) {
SceneInfo& info = (*info_)[index];
for (auto& info: *info_) {

Check warning on line 634 in src/ivoc/scene.cpp

View check run for this annotation

Codecov / codecov/patch

src/ivoc/scene.cpp#L634

Added line #L634 was not covered by tests
if (info.status_ & SceneInfoFixed) {
are_fixed = true;
} else if (info.glyph_ != NULL && (info.status_ & SceneInfoShowing)) {
Expand All @@ -658,8 +651,7 @@ void Scene::print(Printer* canvas, const Allocation& a) const {
// view_transform(canvas, 2, tv);
const Transformer& tv = XYView::current_draw_view()->s2o();
canvas->transform(tv);
for (GlyphIndex index = 0; index < count; ++index) {
SceneInfo& info = (*info_)[index];
for (auto& info: *info_) {

Check warning on line 654 in src/ivoc/scene.cpp

View check run for this annotation

Codecov / codecov/patch

src/ivoc/scene.cpp#L654

Added line #L654 was not covered by tests
if ((info.status_ & SceneInfoFixed) && info.glyph_ != NULL &&
(info.status_ & SceneInfoShowing)) {
Allocation a = info.allocation_;
Expand Down Expand Up @@ -780,9 +772,8 @@ void Scene::save_all(std::ostream& o) {
Sprintf(buf, "objectvar scene_vector_[%ld]", scene_list->size());

Check warning on line 772 in src/ivoc/scene.cpp

View check run for this annotation

Codecov / codecov/patch

src/ivoc/scene.cpp#L771-L772

Added lines #L771 - L772 were not covered by tests
o << buf << std::endl;
}
long count = scene_list->size();
for (long i = 0; i < count; ++i) {
(*scene_list)[i]->mark(false);
for (auto& scene: *scene_list) {
scene->mark(false);

Check warning on line 776 in src/ivoc/scene.cpp

View check run for this annotation

Codecov / codecov/patch

src/ivoc/scene.cpp#L775-L776

Added lines #L775 - L776 were not covered by tests
}
}

Expand Down
7 changes: 4 additions & 3 deletions src/ivoc/symdir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ SymDirectory::~SymDirectory() {
delete item;

Check warning on line 203 in src/ivoc/symdir.cpp

View check run for this annotation

Codecov / codecov/patch

src/ivoc/symdir.cpp#L202-L203

Added lines #L202 - L203 were not covered by tests
}
impl_->symbol_lists_.clear();
impl_->symbol_lists_.shrink_to_fit();

Check warning on line 206 in src/ivoc/symdir.cpp

View check run for this annotation

Codecov / codecov/patch

src/ivoc/symdir.cpp#L205-L206

Added lines #L205 - L206 were not covered by tests
if (impl_->obj_) {
ObjObservable::Detach(impl_->obj_, impl_);
}
Expand Down Expand Up @@ -579,9 +580,9 @@ void SymDirectoryImpl::append(Object* ob) {
symbol_lists_.push_back(new SymbolItem(ob));

Check warning on line 580 in src/ivoc/symdir.cpp

View check run for this annotation

Codecov / codecov/patch

src/ivoc/symdir.cpp#L580

Added line #L580 was not covered by tests
}
void SymDirectoryImpl::un_append(Object* ob) {
for (std::size_t i = 0; i < symbol_lists_.size(); ++i) {
if (symbol_lists_[i]->object() == ob) {
symbol_lists_[i]->no_object();
for (auto& symbol: symbol_lists_) {
if (symbol->object() == ob) {
symbol->no_object();

Check warning on line 585 in src/ivoc/symdir.cpp

View check run for this annotation

Codecov / codecov/patch

src/ivoc/symdir.cpp#L583-L585

Added lines #L583 - L585 were not covered by tests
break;
}
}
Expand Down
4 changes: 1 addition & 3 deletions src/nrncvode/netcvode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6431,7 +6431,6 @@ void NetCvode::vec_remove() {

void NetCvode::playrec_setup() {
long i, j;
long prlc = prl_->size();
fixed_record_->clear();
fixed_play_->clear();
if (gcv_) {
Expand All @@ -6442,8 +6441,7 @@ void NetCvode::playrec_setup() {
}
}
std::vector<PlayRecord*> to_delete{};
for (long iprl = 0; iprl < prlc; ++iprl) {
PlayRecord* pr = (*prl_)[iprl];
for (auto& pr: *prl_) {
if (!pr->pd_) {
// Presumably the recorded value was invalidated elsewhere, e.g. it
// was a voltage of a deleted node, or a range variable of a deleted
Expand Down

0 comments on commit 608870c

Please sign in to comment.