Hello, The attached patch speeds up returnLeafNodes() by over 30% in my tests. Doing returnPackages() only once doesn't gain much, but lazy fetching various lists and avoiding concatenating them does a lot. While at it, changed some has_key()'s to "foo in bar" (has_key is deprecated in favor of the latter).
From 7c852f09baabb7c7f3901b44e2180ad9312759fb Mon Sep 17 00:00:00 2001 From: =?utf-8?q?Ville=20Skytt=C3=A4?= <ville.skytta@xxxxxx> Date: Sun, 1 Mar 2009 23:46:41 +0200 Subject: [PATCH] Speed up returnLeafNodes(). --- yum/packageSack.py | 31 +++++++++++++++++-------------- 1 files changed, 17 insertions(+), 14 deletions(-) diff --git a/yum/packageSack.py b/yum/packageSack.py index 997f4fb..9ad55a9 100644 --- a/yum/packageSack.py +++ b/yum/packageSack.py @@ -238,29 +238,32 @@ class PackageSackBase(object): req = {} orphans = [] + pos = self.returnPackages(repoid=repoid) # prebuild the req dict - for po in self.returnPackages(repoid=repoid): - if not po.requires_names: - continue + for po in pos: for r in po.requires_names: - if not req.has_key(r): + if r not in req: req[r] = set() req[r].add(po) - for po in self.returnPackages(repoid=repoid): + for po in pos: preq = 0 - for p in po.provides_names + po.filelist + po.dirlist + po.ghostlist: - if req.has_key(p): - # Don't count a package that provides its require - s = req[p] - if len(s) > 1 or po not in s: - preq += 1 - break - + # Use getattr for lazy fetching + for pl in ('provides_names', 'filelist', 'dirlist', 'ghostlist'): + for p in getattr(po, pl): + if p in req: + # Don't count a package that provides its require + s = req[p] + if len(s) > 1 or po not in s: + preq += 1 + break + if preq: + break + if preq == 0: orphans.append(po) - + return orphans class MetaSack(PackageSackBase): -- 1.5.6.6
_______________________________________________ Yum mailing list Yum@xxxxxxxxxxxxxxxxx http://lists.baseurl.org/mailman/listinfo/yum