Use a dict over list

feature/regioned_storage
Nikhil 5 years ago
parent f12a44d3c5
commit 7ddbdc7709
  1. 8
      mythril/laser/ethereum/state/account.py

@ -135,20 +135,20 @@ class IteStorageRegion(StorageRegion):
def __init__(self) -> None: def __init__(self) -> None:
"""Constructor for Storage. """Constructor for Storage.
""" """
self.itelist = [] # type: List[Tuple[BitVecFunc, Any]] self.itedict = {} # type: Dict[BitVecFunc, Tuple[BitVecFunc, Any]]
def __getitem__(self, item: BitVecFunc): def __getitem__(self, item: BitVecFunc):
storage = symbol_factory.BitVecVal(0, 256) storage = symbol_factory.BitVecVal(0, 256)
for key, val in self.itelist[::-1]: for key, val in self.itedict.items():
storage = If(item == key, val, storage) storage = If(item == key, val, storage)
return storage return storage
def __setitem__(self, key: BitVecFunc, value): def __setitem__(self, key: BitVecFunc, value):
self.itelist.append((key, value)) self.itedict[key] = (key, value)
def __deepcopy__(self, memodict={}): def __deepcopy__(self, memodict={}):
ite_copy = IteStorageRegion() ite_copy = IteStorageRegion()
ite_copy.itelist = copy(self.itelist) ite_copy.itedict = copy(self.itedict)
return ite_copy return ite_copy

Loading…
Cancel
Save