From c4a095aee57f80695b7637385623f5fdcc8d44dc Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Tue, 10 Mar 2009 03:59:37 +0000 Subject: [PATCH] Optimize dbapi._cpv_sort_ascending() by calling vercmp directly instead of calling pkgcmp. svn path=/main/trunk/; revision=12815 --- pym/portage/dbapi/__init__.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/pym/portage/dbapi/__init__.py b/pym/portage/dbapi/__init__.py index 6bea1e5d3..9956d0999 100644 --- a/pym/portage/dbapi/__init__.py +++ b/pym/portage/dbapi/__init__.py @@ -13,7 +13,7 @@ portage.proxy.lazyimport.lazyimport(globals(), 'portage.locks:unlockfile', 'portage.output:colorize', 'portage.util:cmp_sort_key,writemsg', - 'portage.versions:catpkgsplit,pkgcmp', + 'portage.versions:catpkgsplit,vercmp', ) from portage import auxdbkeys, dep_expand @@ -60,14 +60,12 @@ class dbapi(object): # If the cpv includes explicit -r0, it has to be preserved # for consistency in findname and aux_get calls, so use a # dict to map strings back to their original values. - str_map = {} - for i, cpv in enumerate(cpv_list): - mysplit = tuple(catpkgsplit(cpv)[1:]) - str_map[mysplit] = cpv - cpv_list[i] = mysplit - cpv_list.sort(key=cmp_sort_key(pkgcmp)) - for i, mysplit in enumerate(cpv_list): - cpv_list[i] = str_map[mysplit] + ver_map = {} + for cpv in cpv_list: + ver_map[cpv] = '-'.join(catpkgsplit(cpv)[2:]) + def cmp_cpv(cpv1, cpv2): + return vercmp(ver_map[cpv1], ver_map[cpv2]) + cpv_list.sort(key=cmp_sort_key(cmp_cpv)) def cpv_all(self): """Return all CPVs in the db -- 2.26.2