Skip to content

Commit b32a439

Browse files
Return early if possible in get_user_specified_clinit_body
This makes the function simpler and can avoid some unecessary computation.
1 parent 0dfcf6a commit b32a439

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

jbmc/src/java_bytecode/java_static_initializers.cpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,14 @@ code_blockt get_user_specified_clinit_body(
792792
&class_to_declared_symbols_map)
793793
{
794794
const irep_idt &real_clinit_name = clinit_function_name(class_id);
795+
const auto clinit_func = symbol_table.lookup(real_clinit_name);
796+
if(clinit_func == nullptr)
797+
{
798+
// Case where the real clinit doesn't appear in the symbol table, even
799+
// though their is user specifed one. This may occur when some class
800+
// substitution happened after compilation.
801+
return code_blockt{};
802+
}
795803
const auto class_entry =
796804
static_values_json.find(id2string(strip_java_namespace_prefix(class_id)));
797805
if(class_entry != static_values_json.end())
@@ -817,13 +825,6 @@ code_blockt get_user_specified_clinit_body(
817825
}
818826
}
819827
}
820-
if(symbol_table.lookup(real_clinit_name) == nullptr)
821-
{
822-
// Case where there is a user provided clinit, but the real clinit
823-
// doesn't appear in the symbol table. This may occur when some class
824-
// substitution happened after compilation.
825-
return code_blockt{};
826-
}
827828
code_blockt body;
828829
for(const auto &value_pair : static_field_values)
829830
{
@@ -840,9 +841,7 @@ code_blockt get_user_specified_clinit_body(
840841
return body;
841842
}
842843
}
843-
if(const auto clinit_func = symbol_table.lookup(real_clinit_name))
844-
return code_blockt{{code_function_callt{clinit_func->symbol_expr()}}};
845-
return code_blockt{};
844+
return code_blockt{{code_function_callt{clinit_func->symbol_expr()}}};
846845
}
847846

848847
/// Create static initializer wrappers and possibly user-specified functions for

0 commit comments

Comments
 (0)