Skip to content

Commit 54e5b85

Browse files
committed
Use a const expr to avoid unnecessary detach
While dest.type() is passed as const reference, dest itself is not const in this context and thus irept::add will be used instead of irept::find. This, in turn, results in unnecessary calls to detach and thus breaks sharing and causes memory allocation. This change reduces linking time in some Linux kernel experiments by a further 10%.
1 parent 6f71ff6 commit 54e5b85

File tree

2 files changed

+12
-20
lines changed

2 files changed

+12
-20
lines changed

src/util/rename_symbol.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ bool rename_symbolt::rename(exprt &dest) const
3232

3333
// first look at type
3434

35-
if(have_to_rename(dest.type()))
35+
const exprt &const_dest(dest);
36+
if(have_to_rename(const_dest.type()))
3637
if(!rename(dest.type()))
3738
result=false;
3839

src/util/replace_symbol.cpp

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ bool replace_symbolt::replace(
3535

3636
// first look at type
3737

38-
if(have_to_replace(dest.type()))
38+
const exprt &const_dest(dest);
39+
if(have_to_replace(const_dest.type()))
3940
if(!replace(dest.type()))
4041
result=false;
4142

@@ -94,25 +95,15 @@ bool replace_symbolt::replace(
9495
result=false;
9596
}
9697

97-
const irept &c_sizeof_type=dest.find(ID_C_c_sizeof_type);
98-
99-
if(c_sizeof_type.is_not_nil())
100-
{
101-
typet &type=static_cast<typet &>(dest.add(ID_C_c_sizeof_type));
102-
103-
if(!replace(type))
104-
result=false;
105-
}
98+
const typet &c_sizeof_type =
99+
static_cast<const typet&>(dest.find(ID_C_c_sizeof_type));
100+
if(c_sizeof_type.is_not_nil() && have_to_replace(c_sizeof_type))
101+
result &= replace(static_cast<typet&>(dest.add(ID_C_c_sizeof_type)));
106102

107-
const irept &va_arg_type=dest.find(ID_C_va_arg_type);
108-
109-
if(va_arg_type.is_not_nil())
110-
{
111-
typet &type=static_cast<typet &>(dest.add(ID_C_va_arg_type));
112-
113-
if(!replace(type))
114-
result=false;
115-
}
103+
const typet &va_arg_type =
104+
static_cast<const typet&>(dest.find(ID_C_va_arg_type));
105+
if(va_arg_type.is_not_nil() && have_to_replace(va_arg_type))
106+
result &= replace(static_cast<typet&>(dest.add(ID_C_va_arg_type)));
116107

117108
return result;
118109
}

0 commit comments

Comments
 (0)