def compute_common_fields(self, orig, d): fields = [] if orig is not None: if d is not None: d = d.copy() else: d = {} for ofs in orig: d.setdefault(ofs, self.node_escaped) if d is not None: lst = d.keys() # we always use the "standardized" order of fields sort_descrs(lst) for ofs in lst: try: if orig is None: raise KeyError node = orig[ofs] except KeyError: # field stored at exit, but not read at input. Must # still be allocated, otherwise it will be incorrectly # uninitialized after a guard failure. node = self.node_fromstart specnode = self.intersect(node, d[ofs]) fields.append((ofs, specnode)) return fields
def _get_field_descr_list(self): # this shares only per instance and not per type, but better than nothing _cached_sorted_fields = self._cached_sorted_fields if (_cached_sorted_fields is not None and len(self._fields) == len(_cached_sorted_fields)): lst = self._cached_sorted_fields else: lst = self._fields.keys() sort_descrs(lst) self._cached_sorted_fields = lst return lst
def test_sort_descrs(): class PseudoDescr(AbstractDescr): def __init__(self, n): self.n = n def sort_key(self): return self.n for i in range(17): lst = [PseudoDescr(j) for j in range(i)] lst2 = lst[:] random.shuffle(lst2) sort_descrs(lst2) assert lst2 == lst
def _get_field_descr_list(self): _cached_sorted_fields = self._cached_sorted_fields if (_cached_sorted_fields is not None and len(self._fields) == len(_cached_sorted_fields)): lst = self._cached_sorted_fields else: lst = self._fields.keys() sort_descrs(lst) cache = get_fielddescrlist_cache(self.optimizer.cpu) result = cache.get(lst, None) if result is None: cache[lst] = lst else: lst = result # store on self, to not have to repeatedly get it from the global # cache, which involves sorting self._cached_sorted_fields = lst return lst