From 85286bb8c9cb83f0ce4d5d5e168c8d7cf08ecb89 Mon Sep 17 00:00:00 2001 From: Jens Gerlach Date: Mon, 26 Oct 2015 08:27:24 +0100 Subject: [PATCH 1/3] reduce scope of loop variable(s) --- src/Effect.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/Effect.cpp b/src/Effect.cpp index bccac5480..bcb2d8674 100644 --- a/src/Effect.cpp +++ b/src/Effect.cpp @@ -304,10 +304,7 @@ Effect::add_external_effect(const Effect &e, std::vector call_chai bool Effect::is_read(const Variable *v) const { - vector::size_type len = read_vars.size(); - vector::size_type i; - - for (i = 0; i < len; ++i) { + for (size_t i = 0; i < read_vars.size(); ++i) { if (read_vars[i] == v) { return true; } From 29d5c1268c79da74f51d20aee3db2718e64954b4 Mon Sep 17 00:00:00 2001 From: Jens Gerlach Date: Mon, 26 Oct 2015 13:37:30 +0100 Subject: [PATCH 2/3] fix TODO w.r.t to std::find --- src/Effect.cpp | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/Effect.cpp b/src/Effect.cpp index bcb2d8674..8aa6ff87c 100644 --- a/src/Effect.cpp +++ b/src/Effect.cpp @@ -298,25 +298,25 @@ Effect::add_external_effect(const Effect &e, std::vector call_chai } /* - * TODO: tried doing this with `find', but I couldn't get all the `const's - * right. Gave up; wrote it by hand! + * + * */ bool Effect::is_read(const Variable *v) const { - for (size_t i = 0; i < read_vars.size(); ++i) { - if (read_vars[i] == v) { - return true; + if (std::find(read_vars.begin(), read_vars.end(), v) != read_vars.end()) { + return true; + } + else { + // if we read a struct, presumingly all the fields are read too + // however we can not say the same thing for unions: reading a particular + // unions field can cause unspecified behaviors, while reading the whole + // union won't + if (v->field_var_of && v->field_var_of->type->eType == eStruct) { + return is_read(v->field_var_of); } + return false; } - // if we read a struct, presumingly all the fields are read too - // however we can not say the same thing for unions: reading a particular - // unions field can cause unspecified behaviors, while reading the whole - // union won't - if (v->field_var_of && v->field_var_of->type->eType == eStruct) { - return is_read(v->field_var_of); - } - return false; } /* From 5f53009f8827b603cc8e2315efce57f342060246 Mon Sep 17 00:00:00 2001 From: Jens Gerlach Date: Sat, 31 Oct 2015 11:09:13 +0100 Subject: [PATCH 3/3] remove else from fix --- src/Effect.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Effect.cpp b/src/Effect.cpp index 8aa6ff87c..eb284e42c 100644 --- a/src/Effect.cpp +++ b/src/Effect.cpp @@ -307,16 +307,16 @@ Effect::is_read(const Variable *v) const if (std::find(read_vars.begin(), read_vars.end(), v) != read_vars.end()) { return true; } - else { - // if we read a struct, presumingly all the fields are read too - // however we can not say the same thing for unions: reading a particular - // unions field can cause unspecified behaviors, while reading the whole - // union won't - if (v->field_var_of && v->field_var_of->type->eType == eStruct) { - return is_read(v->field_var_of); - } - return false; + + // if we read a struct, presumingly all the fields are read too + // however we can not say the same thing for unions: reading a particular + // unions field can cause unspecified behaviors, while reading the whole + // union won't + if (v->field_var_of && v->field_var_of->type->eType == eStruct) { + return is_read(v->field_var_of); } + + return false; } /*