diff options
author | Erik Rose <devnull@localhost> | 2014-03-19 01:44:06 -0400 |
---|---|---|
committer | Erik Rose <devnull@localhost> | 2014-03-19 01:44:06 -0400 |
commit | e94580988e6882c90f13af1370510049deca5618 (patch) | |
tree | bb054f3082109eeb183737e614b0d5d49448aad6 | |
parent | e2b70270967cf9661841066ba17805a112cc55cf (diff) | |
download | six-e94580988e6882c90f13af1370510049deca5618.tar.gz |
Select the implementations of dictionary iterator routines at import time for a 20% speed boost.
-rw-r--r-- | CONTRIBUTORS | 3 | ||||
-rw-r--r-- | six.py | 48 |
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 @@ -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: |