Skip to content

Commit 11b1ee6

Browse files
Extract a class_to_declared_symbols method
This is an intermediary commit towards computing this map outside of the get_user_specified_clinit_body function, so that we can avoid going through the whole symbol map at each get_user_specified_clinit_body call.
1 parent 7e742b8 commit 11b1ee6

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

jbmc/src/java_bytecode/java_static_initializers.cpp

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -767,6 +767,20 @@ code_ifthenelset get_clinit_wrapper_body(
767767
return code_ifthenelset(std::move(check_already_run), std::move(init_body));
768768
}
769769

770+
/// \return map associating classes to the symbols they declare
771+
static std::unordered_multimap<irep_idt, symbolt>
772+
class_to_declared_symbols(const symbol_tablet &symbol_table)
773+
{
774+
std::unordered_multimap<irep_idt, symbolt> result;
775+
for(const auto &symbol_pair : symbol_table)
776+
{
777+
const symbolt &symbol = symbol_pair.second;
778+
if(optionalt<irep_idt> declaring = declaring_class(symbol))
779+
result.emplace(*declaring, symbol);
780+
}
781+
return result;
782+
}
783+
770784
code_blockt get_user_specified_clinit_body(
771785
const irep_idt &class_id,
772786
const json_objectt &static_values_json,
@@ -785,12 +799,13 @@ code_blockt get_user_specified_clinit_body(
785799
{
786800
const auto &class_json_object = to_json_object(class_json_value);
787801
std::map<symbol_exprt, jsont> static_field_values;
788-
for(const auto &symbol_pair : symbol_table)
802+
const auto class_to_declared_symbols_map =
803+
class_to_declared_symbols(symbol_table);
804+
for(const auto &symbol_pair :
805+
equal_range(class_to_declared_symbols_map, class_id))
789806
{
790807
const symbolt &symbol = symbol_pair.second;
791-
if(
792-
declaring_class(symbol) && *declaring_class(symbol) == class_id &&
793-
symbol.is_static_lifetime)
808+
if(symbol.is_static_lifetime)
794809
{
795810
const symbol_exprt &static_field_expr = symbol.symbol_expr();
796811
const auto &static_field_entry =

0 commit comments

Comments
 (0)