Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 149900 - A minor change in portage_util.py
Summary: A minor change in portage_util.py
Status: RESOLVED FIXED
Alias: None
Product: Portage Development
Classification: Unclassified
Component: Core (show other bugs)
Hardware: All Linux
: High minor (vote)
Assignee: Portage team
URL:
Whiteboard:
Keywords: InVCS
Depends on:
Blocks: 147007
  Show dependency tree
 
Reported: 2006-10-02 15:07 UTC by Ali Polatel (RETIRED)
Modified: 2006-10-02 20:36 UTC (History)
0 users

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ali Polatel (RETIRED) gentoo-dev 2006-10-02 15:07:38 UTC
User-Agent:       Mozilla/5.0 (X11; U; Linux i686; tr; rv:1.8.0.6) Gecko/20060808 Firefox/1.5.0.6
Build Identifier: 

Here is a small improvement in portage_util.py in function varexpand() which
starts on line 288 ( my portage version is 2.1.2_pre2 btw ) :
"""
def varexpand(mystring,mydict={}):
   try:
       return cexpand[" "+mystring]
   except KeyError:
       pass
"""

This can be replaced with:

def varexpand(mystring,mydict={}):
   if " "+mystring in cexpand.keys():
         return cexpand[" "+mystring]
   ...
which is more efficient than a try,except block   



Reproducible: Always
Comment 1 Zac Medico gentoo-dev 2006-10-02 15:31:07 UTC
(In reply to comment #0)
> This can be replaced with:
> 
> def varexpand(mystring,mydict={}):
>    if " "+mystring in cexpand.keys():
>          return cexpand[" "+mystring]
>    ...
> which is more efficient than a try,except block   

Thanks.  You know, that dict.keys() call is unnecessary. ;)
Comment 2 Zac Medico gentoo-dev 2006-10-02 15:40:44 UTC
This is fixed in svn r4574.  Here's what I did:

	newstring = cexpand.get(" "+mystring, None)
	if newstring is not None:
		return newstring
Comment 3 Ali Polatel (RETIRED) gentoo-dev 2006-10-02 15:46:59 UTC
(In reply to comment #1)
> (In reply to comment #0)
> > This can be replaced with:
> > 
> > def varexpand(mystring,mydict={}):
> >    if " "+mystring in cexpand.keys():
> >          return cexpand[" "+mystring]
> >    ...
> > which is more efficient than a try,except block   
> 
> Thanks.  You know, that dict.keys() call is unnecessary. ;)
> 
Yeah right :-) python is just being too clever sometimes..

Comment 4 Zac Medico gentoo-dev 2006-10-02 20:36:34 UTC
This has been released in 2.1.2_pre2-r2.