[pypy-svn] r25741 - pypy/dist/pypy/rpython/rctypes

arigo at codespeak.net arigo at codespeak.net
Wed Apr 12 22:02:34 CEST 2006


Author: arigo
Date: Wed Apr 12 22:02:33 2006
New Revision: 25741

Modified:
   pypy/dist/pypy/rpython/rctypes/rarray.py
Log:
Some optimizations for the common cases of arrays
(essentially avoiding the address hackery).


Modified: pypy/dist/pypy/rpython/rctypes/rarray.py
==============================================================================
--- pypy/dist/pypy/rpython/rctypes/rarray.py	(original)
+++ pypy/dist/pypy/rpython/rctypes/rarray.py	Wed Apr 12 22:02:33 2006
@@ -7,6 +7,7 @@
 from pypy.annotation.pairtype import pairtype
 from pypy.rpython.rctypes.rmodel import CTypesRefRepr, CTypesValueRepr
 from pypy.rpython.rctypes.rmodel import genreccopy, reccopy
+from pypy.rpython.rctypes.rprimitive import PrimitiveRepr
 
 ArrayType = type(ARRAY(c_int, 10))
 
@@ -67,13 +68,23 @@
     def rtype_setitem((r_array, r_int), hop):
         v_array, v_index, v_item = hop.inputargs(r_array, lltype.Signed,
                                                  r_array.r_item)
-        v_item_c_data = r_array.r_item.get_c_data(hop.llops, v_item)
-        v_c_data = r_array.get_c_data_of_item(hop.llops, v_array, v_index)
-        # copy the whole structure's content over
-        genreccopy(hop.llops, v_item_c_data, v_c_data)
+        if isinstance(r_array.r_item, CTypesRefRepr):
+            # ByRef case
+            v_item_c_data = r_array.r_item.get_c_data(hop.llops, v_item)
+            v_c_data = r_array.get_c_data_of_item(hop.llops, v_array, v_index)
+            # copy the whole structure's content over
+            genreccopy(hop.llops, v_item_c_data, v_c_data)
+        else:
+            # ByValue case (optimization; the above also works in this case)
+            v_newvalue = r_array.r_item.getvalue(hop.llops, v_item)
+            r_array.set_item_value(hop.llops, v_array, v_index, v_newvalue)
 
     def rtype_getitem((r_array, r_int), hop):
         v_array, v_index = hop.inputargs(r_array, lltype.Signed)
+        if isinstance(r_array.r_item, PrimitiveRepr):
+            # primitive case (optimization only)
+            return r_array.get_item_value(hop.llops, v_array, v_index)
+        # normal case
         v_c_data = r_array.get_c_data_of_item(hop.llops, v_array, v_index)
         return r_array.r_item.return_c_data(hop.llops, v_c_data)
 



More information about the Pypy-commit mailing list