Skip to content

Commit

Permalink
Use std::vector instead of std::stack
Browse files Browse the repository at this point in the history
This makes the generics type tracking information traversable, allows for
push_back / pop_back and provides constant time access to any element.
  • Loading branch information
Matthias Güdemann committed Jun 6, 2018
1 parent 6d5e446 commit 7360696
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ const void generic_parameter_specialization_map_keyst::insert_pairs(
const irep_idt &key = pair.first.get_name();
if(generic_parameter_specialization_map.count(key) == 0)
generic_parameter_specialization_map.emplace(
key, std::stack<reference_typet>());
key, std::vector<reference_typet>());
(*generic_parameter_specialization_map.find(key))
.second.push(pair.second);
.second.push_back(pair.second);

// We added something, so pop it when this is destroyed:
erase_keys.push_back(key);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class generic_parameter_specialization_map_keyst
for(const auto key : erase_keys)
{
PRECONDITION(generic_parameter_specialization_map.count(key) != 0);
(*generic_parameter_specialization_map.find(key)).second.pop();
(*generic_parameter_specialization_map.find(key)).second.pop_back();
if((*generic_parameter_specialization_map.find(key)).second.empty())
{
generic_parameter_specialization_map.erase(key);
Expand Down
2 changes: 1 addition & 1 deletion jbmc/src/java_bytecode/select_pointer_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ pointer_typet select_pointer_typet::specialize_generics(
return pointer_type;
}
const pointer_typet &type =
generic_parameter_specialization_map.find(parameter_name)->second.top();
generic_parameter_specialization_map.find(parameter_name)->second.back();

// generic parameters can be adopted from outer classes or superclasses so
// we may need to search for the concrete type recursively
Expand Down
5 changes: 3 additions & 2 deletions jbmc/src/java_bytecode/select_pointer_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@
/// Handle selection of correct pointer type (for example changing abstract
/// classes to concrete versions).

#include <util/optional.h>
#include <util/std_types.h>
#include <stack>
#include <vector>
#include "java_types.h"

typedef std::unordered_map<irep_idt, std::stack<reference_typet>>
typedef std::unordered_map<irep_idt, std::vector<reference_typet>>
generic_parameter_specialization_mapt;

class namespacet;
Expand Down

0 comments on commit 7360696

Please sign in to comment.