[pypy-commit] pypy default: don't switch strategies back and forth if we're calling PySequenceFast_ITEMS and PyList_GET_ITEM alternatively

arigo pypy.commits at gmail.com
Thu Nov 24 10:47:47 EST 2016


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r88637:c4f99ae69793
Date: 2016-11-24 14:52 +0100
http://bitbucket.org/pypy/pypy/changeset/c4f99ae69793/

Log:	don't switch strategies back and forth if we're calling
	PySequenceFast_ITEMS and PyList_GET_ITEM alternatively

diff --git a/pypy/module/cpyext/listobject.py b/pypy/module/cpyext/listobject.py
--- a/pypy/module/cpyext/listobject.py
+++ b/pypy/module/cpyext/listobject.py
@@ -62,12 +62,14 @@
     position must be positive, indexing from the end of the list is not
     supported.  If pos is out of bounds, return NULL and set an
     IndexError exception."""
+    from pypy.module.cpyext.sequence import CPyListStrategy
     if not isinstance(w_list, W_ListObject):
         PyErr_BadInternalCall(space)
     if index < 0 or index >= w_list.length():
         raise oefmt(space.w_IndexError, "list index out of range")
-    w_list.ensure_object_strategy()  # make sure we can return a borrowed obj
-    # XXX ^^^ how does this interact with CPyListStrategy?
+    cpy_strategy = space.fromcache(CPyListStrategy)
+    if w_list.strategy is not cpy_strategy:
+        w_list.ensure_object_strategy() # make sure we can return a borrowed obj
     w_res = w_list.getitem(index)
     return w_res     # borrowed ref
 


More information about the pypy-commit mailing list