[pypy-commit] pypy cppyy-dev: simplify iteration over std::list/map

wlav pypy.commits at gmail.com
Thu Nov 7 18:56:22 EST 2019


Author: Wim Lavrijsen <WLavrijsen at lbl.gov>
Branch: cppyy-dev
Changeset: r97989:466fe5506d3d
Date: 2019-11-07 11:37 -0800
http://bitbucket.org/pypy/pypy/changeset/466fe5506d3d/

Log:	simplify iteration over std::list/map

diff --git a/pypy/module/_cppyy/pythonify.py b/pypy/module/_cppyy/pythonify.py
--- a/pypy/module/_cppyy/pythonify.py
+++ b/pypy/module/_cppyy/pythonify.py
@@ -439,14 +439,17 @@
     # also the fallback on the indexed __getitem__, but that is slower)
     add_checked_item = False
     if name.find('std::vector', 0, 11) != 0:
-        if ('begin' in pyclass.__dict__ and 'end' in pyclass.__dict__):
+        if 'begin' in pyclass.__dict__ and 'end' in pyclass.__dict__:
             if _cppyy._scope_byname(name+'::iterator') or \
                     _cppyy._scope_byname(name+'::const_iterator'):
                 def __iter__(self):
                     i = self.begin()
-                    while i != self.end():
+                    end = self.size()
+                    count = 0
+                    while count != end:
                         yield i.__deref__()
                         i.__preinc__()
+                        count += 1
                     i.__destruct__()
                     raise StopIteration
                 pyclass.__iter__ = __iter__


More information about the pypy-commit mailing list