summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2009-09-22 19:48:26 +0000
committerZac Medico <zmedico@gentoo.org>2009-09-22 19:48:26 +0000
commit26736fa28cf9a37f4ea0cb9ee73f4b0c6a240d28 (patch)
tree4c1f5bf74817f7824bfe5b6c4a96a6d1a4f6f0b4
parentcee4de48aae88c5df32e147784fd53ab5fb3ea09 (diff)
downloadportage-26736fa28cf9a37f4ea0cb9ee73f4b0c6a240d28.tar.gz
portage-26736fa28cf9a37f4ea0cb9ee73f4b0c6a240d28.tar.bz2
portage-26736fa28cf9a37f4ea0cb9ee73f4b0c6a240d28.zip
Do manual unicode handling (instead of using the wrapped os module) in
portdbapi.findname2(), since it's a hotspot. Thanks to Marat Radchenko <marat@slonopotamus.org> for the initial patch. svn path=/main/trunk/; revision=14378
-rw-r--r--pym/portage/dbapi/porttree.py38
1 files changed, 26 insertions, 12 deletions
diff --git a/pym/portage/dbapi/porttree.py b/pym/portage/dbapi/porttree.py
index 90092eaa3..7f20e66fd 100644
--- a/pym/portage/dbapi/porttree.py
+++ b/pym/portage/dbapi/porttree.py
@@ -30,8 +30,10 @@ from portage import eclass_cache, auxdbkeys, doebuild, flatten, \
_eapi_is_deprecated
from portage import os
from portage import _encodings
+from portage import _unicode_decode
from portage import _unicode_encode
+import os as _os
import codecs
import logging
import stat
@@ -448,42 +450,54 @@ class portdbapi(dbapi):
the file we wanted.
"""
if not mycpv:
- return "",0
+ return ("", 0)
mysplit = mycpv.split("/")
psplit = pkgsplit(mysplit[1])
if psplit is None or len(mysplit) != 2:
raise InvalidPackageName(mycpv)
+ # For optimal performace in this hot spot, we do manual unicode
+ # handling here instead of using the wrapped os module.
+ encoding = _encodings['fs']
+ errors = 'strict'
+
if mytree:
mytrees = [mytree]
else:
mytrees = self.porttrees[:]
mytrees.reverse()
- relative_path = os.path.join(mysplit[0], psplit[0],
- mysplit[1] + ".ebuild")
+ relative_path = mysplit[0] + _os.sep + psplit[0] + _os.sep + \
+ mysplit[1] + ".ebuild"
if 'parse-eapi-glep-55' in self.doebuild_settings.features:
glep55_startswith = '%s.ebuild-' % mysplit[1]
for x in mytrees:
- filename = x + os.sep + relative_path
- if os.access(filename, os.R_OK):
+ filename = x + _os.sep + relative_path
+ if _os.access(_unicode_encode(filename,
+ encoding=encoding, errors=errors), _os.R_OK):
return (filename, x)
- pkgdir = os.path.join(x, mysplit[0], psplit[0])
+ pkgdir = _os.path.join(x, mysplit[0], psplit[0])
try:
- files = os.listdir(pkgdir)
+ files = _os.listdir(_unicode_encode(pkgdir,
+ encoding=encoding, errors=errors))
except OSError:
continue
for y in files:
+ try:
+ y = _unicode_decode(y, encoding=encoding, errors=errors)
+ except UnicodeDecodeError:
+ continue
if y.startswith(glep55_startswith):
- return (os.path.join(pkgdir, y), x)
+ return (_os.path.join(pkgdir, y), x)
else:
for x in mytrees:
- file = x + os.sep + relative_path
- if os.access(file, os.R_OK):
- return[file, x]
- return None, 0
+ filename = x + _os.sep + relative_path
+ if _os.access(_unicode_encode(filename,
+ encoding=encoding, errors=errors), _os.R_OK):
+ return (filename, x)
+ return (None, 0)
def _metadata_process(self, cpv, ebuild_path, repo_path):
"""