Author: Carl Friedrich Bolz <cfb...@gmx.de> Branch: Changeset: r78732:477e0e47a7cb Date: 2015-07-31 20:11 +0200 http://bitbucket.org/pypy/pypy/changeset/477e0e47a7cb/
Log: a bit just because, use sets instead of dicts with None/True values diff --git a/rpython/translator/backendopt/malloc.py b/rpython/translator/backendopt/malloc.py --- a/rpython/translator/backendopt/malloc.py +++ b/rpython/translator/backendopt/malloc.py @@ -10,9 +10,9 @@ def __init__(self, (block, var)): assert isinstance(var, Variable) - self.variables = {(block, var) : True} - self.creationpoints = {} # set of ("type of creation point", ...) - self.usepoints = {} # set of ("type of use point", ...) + self.variables = {(block, var)} + self.creationpoints = set() # set of ("type of creation point", ...) + self.usepoints = set() # set of ("type of use point", ...) def absorb(self, other): self.variables.update(other.variables) @@ -126,11 +126,11 @@ def set_creation_point(block, var, *cp): _, _, info = lifetimes.find((block, var)) - info.creationpoints[cp] = True + info.creationpoints.add(cp) def set_use_point(block, var, *up): _, _, info = lifetimes.find((block, var)) - info.usepoints[up] = True + info.usepoints.add(up) def union(block1, var1, block2, var2): if isinstance(var1, Variable): @@ -170,7 +170,7 @@ if isinstance(node.last_exc_value, Variable): set_creation_point(node.prevblock, node.last_exc_value, "last_exc_value") - d = {} + d = set() for i, arg in enumerate(node.args): union(node.prevblock, arg, node.target, node.target.inputargs[i]) @@ -181,7 +181,7 @@ # will disable malloc optimization (aliasing problems) set_use_point(node.prevblock, arg, "dup", node, i) else: - d[arg] = True + d.add(arg) return lifetimes.infos() @@ -189,7 +189,7 @@ """Try to inline the mallocs creation and manipulation of the Variables in the given LifeTime.""" # the values must be only ever created by a "malloc" - lltypes = {} + lltypes = set() for cp in info.creationpoints: if cp[0] != "op": return False @@ -199,18 +199,19 @@ if not self.inline_type(op.args[0].value): return False - lltypes[op.result.concretetype] = True + lltypes.add(op.result.concretetype) # there must be a single largest malloced GcStruct; # all variables can point to it or to initial substructures if len(lltypes) != 1: return False - STRUCT = self.get_STRUCT(lltypes.keys()[0]) + concretetype, = lltypes + STRUCT = self.get_STRUCT(concretetype) # must be only ever accessed via getfield/setfield/getsubstruct/ # direct_fieldptr, or touched by ptr_iszero/ptr_nonzero. # Note that same_as and cast_pointer are not recorded in usepoints. - self.accessed_substructs = {} + self.accessed_substructs = set() for up in info.usepoints: if up[0] != "op": @@ -259,8 +260,8 @@ variables_by_block = {} for block, var in info.variables: - vars = variables_by_block.setdefault(block, {}) - vars[var] = True + vars = variables_by_block.setdefault(block, set()) + vars.add(var) count = [0] @@ -269,10 +270,10 @@ # look for variables arriving from outside the block newvarsmap = None newinputargs = [] - inputvars = {} + inputvars = set() for var in block.inputargs: if var in vars: - inputvars[var] = None + inputvars.add(var) if newvarsmap is None: newvarsmap = {} for key in self.flatnames: @@ -292,7 +293,7 @@ if self.check_malloc(op) and op.result in vars: vars_created_here.append(op.result) for var in vars_created_here: - self.flowin(block, count, {var: True}, newvarsmap=None) + self.flowin(block, count, {var}, newvarsmap=None) return count[0] @@ -370,7 +371,7 @@ name = op.args[1].value if not isinstance(name, str): # access by index name = 'item%d' % (name,) - self.accessed_substructs[S, name] = True + self.accessed_substructs.add((S, name)) def inline_type(self, TYPE): return True @@ -493,7 +494,7 @@ else: newvarsmap[key] = op.args[2] elif op.opname in ("same_as", "cast_pointer"): - vars[op.result] = True + vars.add(op.result) # Consider the two pointers (input and result) as # equivalent. We can, and indeed must, use the same # flattened list of variables for both, as a "setfield" @@ -508,7 +509,7 @@ if equiv: # exactly like a cast_pointer assert op.result not in vars - vars[op.result] = True + vars.add(op.result) else: # do it with a getsubstruct on the independently # malloc'ed GcStruct _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit