Skip to content

Commit 032f33b

Browse files
author
Daniel Kroening
authored
Merge pull request #2971 from JohnDumbell/jd/bugfix/unnecessary_class_hierarchy_copy
Stop unneccessary copies of class_hierarchyt
2 parents 6e3ac87 + 00550cd commit 032f33b

File tree

4 files changed

+23
-26
lines changed

4 files changed

+23
-26
lines changed

jbmc/src/java_bytecode/java_bytecode_convert_method_class.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ class java_bytecode_convert_methodt:public messaget
129129
bool method_has_this;
130130
std::map<irep_idt, bool> class_has_clinit_method;
131131
std::map<irep_idt, bool> any_superclass_has_clinit_method;
132-
class_hierarchyt class_hierarchy;
132+
const class_hierarchyt &class_hierarchy;
133133

134134
enum instruction_sizet
135135
{

src/goto-programs/class_hierarchy.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ class class_hierarchyt
5757

5858
void operator()(const symbol_tablet &);
5959

60+
class_hierarchyt() = default;
61+
class_hierarchyt(const class_hierarchyt &) = delete;
62+
class_hierarchyt &operator=(const class_hierarchyt &) = delete;
63+
6064
// transitively gets all children
6165
idst get_children_trans(const irep_idt &id) const
6266
{

src/goto-programs/resolve_inherited_component.cpp

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,14 @@
1010

1111
#include "resolve_inherited_component.h"
1212

13-
/// See the operator() method comment.
14-
/// \param symbol_table: The symbol table to resolve the component against
15-
resolve_inherited_componentt::resolve_inherited_componentt(
16-
const symbol_tablet &symbol_table):
17-
symbol_table(symbol_table)
18-
{
19-
class_hierarchy(symbol_table);
20-
}
21-
2213
/// See the operator() method comment
2314
/// \param symbol_table: The symbol table to resolve the component against
2415
/// \param class_hierarchy: A prebuilt class_hierachy based on the symbol_table
2516
///
2617
resolve_inherited_componentt::resolve_inherited_componentt(
27-
const symbol_tablet &symbol_table, const class_hierarchyt &class_hierarchy):
28-
class_hierarchy(class_hierarchy),
29-
symbol_table(symbol_table)
18+
const symbol_tablet &symbol_table,
19+
const class_hierarchyt &clas_hierarchy)
20+
: class_hierarchy(clas_hierarchy), symbol_table(symbol_table)
3021
{
3122
// We require the class_hierarchy to be already populated if we are being
3223
// supplied it.
@@ -67,18 +58,21 @@ resolve_inherited_componentt::inherited_componentt
6758
return inherited_componentt(current_class, component_name);
6859
}
6960

70-
const class_hierarchyt::idst &parents=
71-
class_hierarchy.class_map[current_class].parents;
72-
73-
if(include_interfaces)
74-
{
75-
classes_to_visit.insert(
76-
classes_to_visit.end(), parents.begin(), parents.end());
77-
}
78-
else
61+
const auto current_class_id = class_hierarchy.class_map.find(current_class);
62+
if(current_class_id != class_hierarchy.class_map.end())
7963
{
80-
if(!parents.empty())
81-
classes_to_visit.push_back(parents.front());
64+
const class_hierarchyt::idst &parents = current_class_id->second.parents;
65+
66+
if(include_interfaces)
67+
{
68+
classes_to_visit.insert(
69+
classes_to_visit.end(), parents.begin(), parents.end());
70+
}
71+
else
72+
{
73+
if(!parents.empty())
74+
classes_to_visit.push_back(parents.front());
75+
}
8276
}
8377
}
8478

src/goto-programs/resolve_inherited_component.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
class resolve_inherited_componentt
2222
{
2323
public:
24-
explicit resolve_inherited_componentt(const symbol_tablet &symbol_table);
2524
resolve_inherited_componentt(
2625
const symbol_tablet &symbol_table, const class_hierarchyt &class_hierarchy);
2726

@@ -70,7 +69,7 @@ class resolve_inherited_componentt
7069
const irep_idt &component_name,
7170
const irep_idt &user_class_name);
7271

73-
class_hierarchyt class_hierarchy;
72+
const class_hierarchyt &class_hierarchy;
7473
const symbol_tablet &symbol_table;
7574
};
7675

0 commit comments

Comments
 (0)