Skip to content

Commit 7e31784

Browse files
committed
Add a new constructor to java_bytecode_parse_treet
Constructing a java_bytecode_parse_treet from an irep_idt avoids two uses of short-lived local variables.
1 parent d197e6e commit 7e31784

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

jbmc/src/java_bytecode/java_bytecode_parse_tree.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,11 @@ struct java_bytecode_parse_treet
199199
{
200200
classt() = default;
201201

202+
/// Create a class \p name.
203+
explicit classt(const irep_idt &name) : name(name)
204+
{
205+
}
206+
202207
// Disallow copy construction and copy assignment, but allow move
203208
// construction and move assignment.
204209
#ifndef _MSC_VER // Ommit this on MS VC2013 as move is not supported.
@@ -307,9 +312,14 @@ struct java_bytecode_parse_treet
307312
typedef std::set<irep_idt> class_refst;
308313
class_refst class_refs;
309314

310-
bool loading_successful;
315+
bool loading_successful = false;
316+
317+
/// An empty bytecode parse tree, no class name set
318+
java_bytecode_parse_treet() = default;
311319

312-
java_bytecode_parse_treet():loading_successful(false)
320+
/// Create a blank parse tree for class \p class_name.
321+
explicit java_bytecode_parse_treet(const irep_idt &class_name)
322+
: parsed_class(class_name)
313323
{
314324
}
315325
};

jbmc/src/java_bytecode/java_class_loader.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,7 @@ java_class_loadert::get_parse_tree(
120120
if(!class_loader_limit.load_class_file(class_name_to_jar_file(class_name)))
121121
{
122122
debug() << "not loading " << class_name << " because of limit" << eom;
123-
java_bytecode_parse_treet parse_tree;
124-
parse_tree.parsed_class.name = class_name;
125-
parse_trees.push_back(std::move(parse_tree));
123+
parse_trees.emplace_back(class_name);
126124
return parse_trees;
127125
}
128126

@@ -179,9 +177,7 @@ java_class_loadert::get_parse_tree(
179177

180178
// Not found or failed to load
181179
warning() << "failed to load class `" << class_name << '\'' << eom;
182-
java_bytecode_parse_treet parse_tree;
183-
parse_tree.parsed_class.name=class_name;
184-
parse_trees.push_back(std::move(parse_tree));
180+
parse_trees.emplace_back(class_name);
185181
return parse_trees;
186182
}
187183

0 commit comments

Comments
 (0)