[pypy-commit] pypy default: convert zip to app-level, it's a tad faster this way. also, more app-level code makes me happy
alex_gaynor
noreply at buildbot.pypy.org
Thu Oct 20 06:04:34 CEST 2011
Author: Alex Gaynor <alex.gaynor at gmail.com>
Branch:
Changeset: r48253:868ae3832ed8
Date: 2011-10-20 00:04 -0400
http://bitbucket.org/pypy/pypy/changeset/868ae3832ed8/
Log: convert zip to app-level, it's a tad faster this way. also, more
app-level code makes me happy
diff --git a/pypy/module/__builtin__/__init__.py b/pypy/module/__builtin__/__init__.py
--- a/pypy/module/__builtin__/__init__.py
+++ b/pypy/module/__builtin__/__init__.py
@@ -23,6 +23,7 @@
'map' : 'app_functional.map',
'reduce' : 'app_functional.reduce',
'filter' : 'app_functional.filter',
+ 'zip' : 'app_functional.zip',
'vars' : 'app_inspect.vars',
'dir' : 'app_inspect.dir',
@@ -89,7 +90,6 @@
'enumerate' : 'functional.W_Enumerate',
'min' : 'functional.min',
'max' : 'functional.max',
- 'zip' : 'functional.zip',
'reversed' : 'functional.reversed',
'super' : 'descriptor.W_Super',
'staticmethod' : 'descriptor.StaticMethod',
diff --git a/pypy/module/__builtin__/app_functional.py b/pypy/module/__builtin__/app_functional.py
--- a/pypy/module/__builtin__/app_functional.py
+++ b/pypy/module/__builtin__/app_functional.py
@@ -162,4 +162,21 @@
item = seq[i]
if func(item):
result.append(item)
- return tuple(result)
\ No newline at end of file
+ return tuple(result)
+
+def zip(*sequences):
+ """zip(seq1 [, seq2 [...]]) -> [(seq1[0], seq2[0] ...), (...)]
+
+Return a list of tuples, where each tuple contains the i-th element
+from each of the argument sequences. The returned list is truncated
+in length to the length of the shortest argument sequence."""
+ if not sequences:
+ return []
+ result = []
+ iterators = [iter(seq) for seq in sequences]
+ while True:
+ try:
+ items = [next(it) for it in iterators]
+ except StopIteration:
+ return result
+ result.append(tuple(items))
diff --git a/pypy/module/__builtin__/functional.py b/pypy/module/__builtin__/functional.py
--- a/pypy/module/__builtin__/functional.py
+++ b/pypy/module/__builtin__/functional.py
@@ -201,27 +201,6 @@
"""
return min_max(space, __args__, "min")
- at unwrap_spec(sequences_w="args_w")
-def zip(space, sequences_w):
- """Return a list of tuples, where the nth tuple contains every nth item of
- each collection.
-
- If the collections have different lengths, zip returns a list as long as the
- shortest collection, ignoring the trailing items in the other collections.
- """
- if not sequences_w:
- return space.newlist([])
- result_w = []
- iterators_w = [space.iter(w_seq) for w_seq in sequences_w]
- while True:
- try:
- items_w = [space.next(w_it) for w_it in iterators_w]
- except OperationError, e:
- if not e.match(space, space.w_StopIteration):
- raise
- return space.newlist(result_w)
- result_w.append(space.newtuple(items_w))
-
class W_Enumerate(Wrappable):
def __init__(self, w_iter, w_start):
More information about the pypy-commit
mailing list