Some minor optimizations

In the case of singlefile this doesn't help much as the whole
implementation is algorithmically flawed. It's not like i care enough to
make the code even more complicated though.
This commit is contained in:
Markus Unterwaditzer 2014-06-29 19:03:49 +02:00
parent 6a63dcec81
commit e4ae04aaa1
2 changed files with 5 additions and 12 deletions

View file

@ -10,7 +10,7 @@
from .base import Item, Storage
from ..exceptions import NotFoundError
from ..utils import expand_path, get_password, request
from ..utils.compat import text_type, urlparse
from ..utils.compat import iteritems, text_type, urlparse
from ..utils.vobject import split_collection
USERAGENT = 'vdirsyncer'
@ -107,17 +107,14 @@ class HttpStorage(Storage):
def list(self):
r = request('GET', self.url, **self._settings)
self._items = {}
rv = []
for item in split_collection(r.text):
item = Item(item)
href = self._get_href(item)
etag = item.hash
self._items[href] = item, etag
rv.append((href, etag))
# we can't use yield here because we need to populate our
# dict even if the user doesn't exhaust the iterator
return rv
return ((href, etag) for href, (item, etag) in iteritems(self._items))
def get(self, href):
if self._items is None:

View file

@ -12,7 +12,7 @@ import collections
from .. import exceptions, log
from .base import Item, Storage
from ..utils import checkfile, expand_path, safe_write
from ..utils.compat import itervalues
from ..utils.compat import iteritems, itervalues
from ..utils.vobject import join_collection, split_collection
logger = log.get(__name__)
@ -94,17 +94,13 @@ class SingleFileStorage(Storage):
if not text:
return ()
rv = []
for item in split_collection(text):
item = Item(item)
href = self._get_href(item)
etag = item.hash
self._items[href] = item, etag
rv.append((href, etag))
# we can't use yield here because we need to populate our
# dict even if the user doesn't exhaust the iterator
return rv
return ((href, etag) for href, (item, etag) in iteritems(self._items))
def get(self, href):
if self._items is None: