From a95743183720c75f0af8a454dcef788d99a3851d Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Thu, 20 Nov 2008 21:02:40 +0000 Subject: Inside _parse_data(), don't rely on the magic 22 line count for the flat_list format, since it doesn't make a significant performance difference and it places an artificial limit on the number of keys that can be stored. svn path=/main/trunk/; revision=12008 --- pym/portage/cache/metadata.py | 45 +++++++++++++++++-------------------------- 1 file changed, 18 insertions(+), 27 deletions(-) (limited to 'pym') diff --git a/pym/portage/cache/metadata.py b/pym/portage/cache/metadata.py index 1c65ee8be..c3c83a019 100644 --- a/pym/portage/cache/metadata.py +++ b/pym/portage/cache/metadata.py @@ -3,7 +3,7 @@ # License: GPL2 # $Id$ -import os, stat, types +import os, re, stat, types from portage.cache import flat_hash import portage.eclass_cache from portage.cache.template import reconstruct_eclasses @@ -22,6 +22,8 @@ class database(flat_hash.database): autocommits = True + _hashed_re = re.compile('^(\\w+)=([^\n]*)') + def __init__(self, location, *args, **config): loc = location super(database, self).__init__(location, *args, **config) @@ -33,34 +35,23 @@ class database(flat_hash.database): def _parse_data(self, data, cpv): - # easy attempt first. + _hashed_re_match = self._hashed_re.match data = list(data) - if len(data) != magic_line_count: - d = flat_hash.database._parse_data(self, data, cpv) - else: - # this one's interesting. - d = {} - - for line in data: - # yes, meant to iterate over a string. - hashed = False - # poor mans enumerate. replace when python 2.3 is required - for idx, c in zip(range(len(line)), line): - if not c.isalpha(): - if c == "=" and idx > 0: - hashed = True - d[line[:idx]] = line[idx + 1:].rstrip("\n") - elif c == "_" or c.isdigit(): - continue - break + d = {} - if not hashed: - # non hashed. - d.clear() - # poor mans enumerate. replace when python 2.3 is required - for idx, key in zip(range(len(self.auxdbkey_order)), self.auxdbkey_order): - d[key] = data[idx].strip() - break + for line in data: + hashed = False + hashed_match = _hashed_re_match(line) + if hashed_match is None: + d.clear() + try: + for i, key in enumerate(self.auxdbkey_order): + d[key] = data[i].rstrip("\n") + except IndexError: + pass + break + else: + d[hashed_match.group(1)] = hashed_match.group(2) if "_eclasses_" not in d: if "INHERITED" in d: -- cgit v1.2.3-1-g7c22