bitbake/data_smart: Optimise the data store iterator

Since we're going to creat the seen set() anyway, we might as well use
it directly. If we don't do this, we see thousands of function calls
with associated overhead on profiles.

(Bitbake rev: 9d43e3279895639ee4899df635f2546c7ee13737)

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Richard Purdie
2011-06-10 17:23:33 +01:00
parent fb38001789
commit cc2a8ff522

View File

@@ -401,18 +401,20 @@ class DataSmart(MutableMapping):
yield key yield key
def __iter__(self): def __iter__(self):
seen = set() def keylist(d):
def _keys(d): klist = set()
if "_data" in d:
for key in _keys(d["_data"]):
yield key
for key in d: for key in d:
if key != "_data": if key == "_data":
if not key in seen: continue
seen.add(key) klist.add(key)
yield key
return _keys(self.dict) if "_data" in d:
klist |= keylist(d["_data"])
return klist
for k in keylist(self.dict):
yield k
def __len__(self): def __len__(self):
return len(frozenset(self)) return len(frozenset(self))