Skip to content

Commit d7c15ae

Browse files
author
thk123
committed
Use pointers in is_type_at_least_as_const_as
To avoid unnecessary temporary objects, use a pointer when checking for const preservation. Note we now need to compare the ID against NIL rather than the empty string since the non-const version of subtype returns a new irept with no id, but the const version returns the nil data structure.
1 parent 4607e73 commit d7c15ae

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

src/analyses/does_remove_const.cpp

+9-9
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ bool does_remove_constt::operator()() const
6666

6767
// Compare the types recursively for a point where the rhs is more
6868
// const that the lhs
69-
if(!is_type_at_least_as_const_as(lhs_type, rhs_type))
69+
if(!is_type_at_least_as_const_as(&lhs_type, &rhs_type))
7070
{
7171
return true;
7272
}
@@ -107,7 +107,7 @@ bool does_remove_constt::does_expr_lose_const(const exprt &expr) const
107107
if(base_type_eq(op_type, root_type, ns))
108108
{
109109
// Is this child more const-qualified than the root
110-
if(!is_type_at_least_as_const_as(root_type, op_type))
110+
if(!is_type_at_least_as_const_as(&root_type, &op_type))
111111
{
112112
return true;
113113
}
@@ -146,22 +146,22 @@ Function: does_remove_constt::is_type_at_least_as_const_as
146146
\*******************************************************************/
147147

148148
bool does_remove_constt::is_type_at_least_as_const_as(
149-
typet type_more_const, typet type_compare) const
149+
const typet *type_more_const, const typet *type_compare) const
150150
{
151-
while(!type_compare.id().empty() && !type_more_const.id().empty())
151+
while(type_compare->id()!=ID_nil && type_more_const->id()!=ID_nil)
152152
{
153-
const c_qualifierst rhs_qualifiers(type_compare);
154-
const c_qualifierst lhs_qualifiers(type_more_const);
153+
const c_qualifierst rhs_qualifiers(*type_compare);
154+
const c_qualifierst lhs_qualifiers(*type_more_const);
155155
if(rhs_qualifiers.is_constant && !lhs_qualifiers.is_constant)
156156
{
157157
return false;
158158
}
159159

160-
type_compare=type_compare.subtype();
161-
type_more_const=type_more_const.subtype();
160+
type_compare=&type_compare->subtype();
161+
type_more_const=&type_more_const->subtype();
162162
}
163163

164164
// Both the types should have the same number of subtypes
165-
assert(type_compare.id().empty() && type_more_const.id().empty());
165+
assert(type_compare->id()==ID_nil && type_more_const->id()==ID_nil);
166166
return true;
167167
}

src/analyses/does_remove_const.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class does_remove_constt
2222
bool does_expr_lose_const(const exprt &expr) const;
2323

2424
bool is_type_at_least_as_const_as(
25-
typet type_more_const, typet type_compare) const;
25+
const typet *type_more_const, const typet *type_compare) const;
2626

2727
const goto_programt &goto_program;
2828
const namespacet &ns;

0 commit comments

Comments
 (0)