Author: Antonio Cuni <[email protected]>
Branch: fast_cffi_list_init
Changeset: r67239:0cdf4e71d831
Date: 2013-10-09 15:34 +0200
http://bitbucket.org/pypy/pypy/changeset/0cdf4e71d831/
Log: shuffle things around and kill a bit of code duplication
diff --git a/rpython/rlib/rarray.py b/rpython/rlib/rarray.py
--- a/rpython/rlib/rarray.py
+++ b/rpython/rlib/rarray.py
@@ -1,5 +1,6 @@
from rpython.annotator import model as annmodel
from rpython.annotator.listdef import ListDef
+from rpython.rlib.objectmodel import specialize
from rpython.rtyper.lltypesystem import lltype, llmemory
from rpython.rtyper.extregistry import ExtRegistryEntry
from rpython.tool.pairtype import pair
@@ -8,7 +9,11 @@
for i, item in enumerate(lst):
array[i] = item
-
+def populate_list_from_raw_array(lst, array, length):
+ lst[:] = [array[i] for i in range(length)]
+
+
+
class Entry(ExtRegistryEntry):
_about_ = copy_list_to_raw_array
@@ -21,27 +26,6 @@
return hop.gendirectcall(ll_copy_list_to_raw_array, v_list, v_buf)
-def ll_copy_list_to_raw_array(ll_list, dst_ptr):
- # this code is delicate: we must ensure that there are no GC operations
- # between here and the call to raw_memcopy
- #
- # start of no-GC section
- src_ptr = ll_list.ll_items()
- src_adr = llmemory.cast_ptr_to_adr(src_ptr)
- src_adr += llmemory.itemoffsetof(lltype.typeOf(src_ptr).TO, 0) # skip the
GC header
- #
- dst_adr = llmemory.cast_ptr_to_adr(dst_ptr)
- dst_adr += llmemory.itemoffsetof(lltype.typeOf(dst_ptr).TO, 0)
- #
- ITEM = lltype.typeOf(dst_ptr).TO.OF
- size = llmemory.sizeof(ITEM) * ll_list.ll_length()
- llmemory.raw_memcopy(src_adr, dst_adr, size)
- # end of no-GC section
-
-
-def populate_list_from_raw_array(lst, array, length):
- lst[:] = [array[i] for i in range(length)]
-
class Entry(ExtRegistryEntry):
_about_ = populate_list_from_raw_array
@@ -57,17 +41,32 @@
return hop.gendirectcall(ll_populate_list_from_raw_array, v_list,
v_buf, v_length)
[email protected]()
+def get_raw_buf(ptr):
+ ofs = llmemory.itemoffsetof(lltype.typeOf(ptr).TO, 0)
+ return llmemory.cast_ptr_to_adr(ptr) + ofs
+get_raw_buf._always_inline_ = True
+
+
+def ll_copy_list_to_raw_array(ll_list, dst_ptr):
+ # this code is delicate: we must ensure that there are no GC operations
+ # around the call to raw_memcopy
+ #
+ ITEM = lltype.typeOf(dst_ptr).TO.OF
+ size = llmemory.sizeof(ITEM) * ll_list.ll_length()
+ # start of no-GC section
+ src_adr = get_raw_buf(ll_list.ll_items())
+ dst_adr = get_raw_buf(dst_ptr)
+ llmemory.raw_memcopy(src_adr, dst_adr, size)
+ # end of no-GC section
+
+
def ll_populate_list_from_raw_array(ll_list, src_ptr, length):
- ll_list._ll_resize(length)
- ll_items = ll_list.ll_items()
- #
- # start of no-GC section
- src_adr = llmemory.cast_ptr_to_adr(src_ptr)
- src_adr += llmemory.itemoffsetof(lltype.typeOf(src_ptr).TO, 0)
- dst_adr = llmemory.cast_ptr_to_adr(ll_items)
- dst_adr += llmemory.itemoffsetof(lltype.typeOf(ll_items).TO, 0) # skip the
GC header
- #
ITEM = lltype.typeOf(src_ptr).TO.OF
size = llmemory.sizeof(ITEM) * length
+ ll_list._ll_resize(length)
+ # start of no-GC section
+ src_adr = get_raw_buf(src_ptr)
+ dst_adr = get_raw_buf(ll_list.ll_items())
llmemory.raw_memcopy(src_adr, dst_adr, size)
# end of no-GC section
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit