summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErik Rose <devnull@localhost>2014-03-19 01:44:06 -0400
committerErik Rose <devnull@localhost>2014-03-19 01:44:06 -0400
commit3743d490c0ace56ac5936ef6770071ce6100a598 (patch)
treebb054f3082109eeb183737e614b0d5d49448aad6
parent46c3f82e5b9dd1adf011c69ad85491f6541bdd17 (diff)
downloadsix-git-3743d490c0ace56ac5936ef6770071ce6100a598.tar.gz
Select the implementations of dictionary iterator routines at import time for a 20% speed boost.
-rw-r--r--CONTRIBUTORS3
-rw-r--r--six.py48
2 files changed, 28 insertions, 23 deletions
diff --git a/CONTRIBUTORS b/CONTRIBUTORS
index 8f9412f..c828a3d 100644
--- a/CONTRIBUTORS
+++ b/CONTRIBUTORS
@@ -1,6 +1,6 @@
The primary author and maintainer of six is Benjamin Peterson. He would like to
acknowledge the following people who submitted bug reports, pull requests, and
-otherwised worked to improve six:
+otherwise worked to improve six:
Marc Abramowitz
Aymeric Augustin
@@ -11,6 +11,7 @@ Ben Darnell
Alexander Lukanin
James Mills
Sridhar Ratnakumar
+Erik Rose
Miroslav Shubernetskiy
If you think you belong on this list, please let me know! --Benjamin
diff --git a/six.py b/six.py
index 019130f..c3f0c05 100644
--- a/six.py
+++ b/six.py
@@ -418,11 +418,6 @@ if PY3:
_func_code = "__code__"
_func_defaults = "__defaults__"
_func_globals = "__globals__"
-
- _iterkeys = "keys"
- _itervalues = "values"
- _iteritems = "items"
- _iterlists = "lists"
else:
_meth_func = "im_func"
_meth_self = "im_self"
@@ -432,11 +427,6 @@ else:
_func_defaults = "func_defaults"
_func_globals = "func_globals"
- _iterkeys = "iterkeys"
- _itervalues = "itervalues"
- _iteritems = "iteritems"
- _iterlists = "iterlists"
-
try:
advance_iterator = next
@@ -485,21 +475,35 @@ get_function_defaults = operator.attrgetter(_func_defaults)
get_function_globals = operator.attrgetter(_func_globals)
-def iterkeys(d, **kw):
- """Return an iterator over the keys of a dictionary."""
- return iter(getattr(d, _iterkeys)(**kw))
+if PY3:
+ def iterkeys(d, **kw):
+ return iter(d.keys(**kw))
+
+ def itervalues(d, **kw):
+ return iter(d.values(**kw))
+
+ def iteritems(d, **kw):
+ return iter(d.items(**kw))
+
+ def iterlists(d, **kw):
+ return iter(d.lists(**kw))
+else:
+ def iterkeys(d, **kw):
+ return iter(d.iterkeys(**kw))
+
+ def itervalues(d, **kw):
+ return iter(d.itervalues(**kw))
-def itervalues(d, **kw):
- """Return an iterator over the values of a dictionary."""
- return iter(getattr(d, _itervalues)(**kw))
+ def iteritems(d, **kw):
+ return iter(d.iteritems(**kw))
-def iteritems(d, **kw):
- """Return an iterator over the (key, value) pairs of a dictionary."""
- return iter(getattr(d, _iteritems)(**kw))
+ def iterlists(d, **kw):
+ return iter(d.iterlists(**kw))
-def iterlists(d, **kw):
- """Return an iterator over the (key, [values]) pairs of a dictionary."""
- return iter(getattr(d, _iterlists)(**kw))
+iterkeys.__doc__ = """Return an iterator over the keys of a dictionary."""
+itervalues.__doc__ = """Return an iterator over the values of a dictionary."""
+iteritems.__doc__ = """Return an iterator over the (key, value) pairs of a dictionary."""
+iterlists.__doc__ = """Return an iterator over the (key, [values]) pairs of a dictionary."""
if PY3: