[pypy-commit] pypy length-hint: use the more official interface instead of hacks
fijal
noreply at buildbot.pypy.org
Wed Nov 14 20:23:11 CET 2012
Author: Maciej Fijalkowski <fijall at gmail.com>
Branch: length-hint
Changeset: r58909:3d0895a129c7
Date: 2012-11-14 13:54 +0100
http://bitbucket.org/pypy/pypy/changeset/3d0895a129c7/
Log: use the more official interface instead of hacks
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
@@ -4,7 +4,7 @@
"""
from __future__ import with_statement
import operator
-from __pypy__ import resizelist_hint
+from __pypy__ import resizelist_hint, newlist_hint
# ____________________________________________________________
@@ -109,15 +109,8 @@
else:
return result
-def _newlist_hint(length_hint):
- """Return an empty list with an underlying capacity of length_hint"""
- result = []
- resizelist_hint(result, length_hint)
- return result
-
class _ManagedNewlistHint(object):
-
- """Context manager returning a _newlist_hint upon entry.
+ """ Context manager returning a newlist_hint upon entry.
Upon exit the list's underlying capacity will be cut back to match
its length if necessary (incase the initial length_hint was too
@@ -126,7 +119,7 @@
def __init__(self, length_hint):
self.length_hint = length_hint
- self.list = _newlist_hint(length_hint)
+ self.list = newlist_hint(length_hint)
def __enter__(self):
return self.list
@@ -183,7 +176,7 @@
if func is bool and type(string) is str_type:
return string
length = len(string)
- result = _newlist_hint(length)
+ result = newlist_hint(length)
for i in range(length):
# You must call __getitem__ on the strings, simply iterating doesn't
# work :/
@@ -196,7 +189,7 @@
def _filter_tuple(func, seq):
length = len(seq)
- result = _newlist_hint(length)
+ result = newlist_hint(length)
for i in range(length):
# Again, must call __getitem__, at least there are tests.
item = seq[i]
More information about the pypy-commit
mailing list