Author: Antonio Cuni <[email protected]>
Branch: faster-rstruct-2
Changeset: r91249:be9e1d6fe67b
Date: 2017-05-11 16:14 +0200
http://bitbucket.org/pypy/pypy/changeset/be9e1d6fe67b/
Log: reduce code duplication
diff --git a/rpython/rtyper/test/test_llop.py b/rpython/rtyper/test/test_llop.py
--- a/rpython/rtyper/test/test_llop.py
+++ b/rpython/rtyper/test/test_llop.py
@@ -6,11 +6,13 @@
from rpython.rtyper.annlowlevel import llstr
from rpython.rlib.rarithmetic import r_singlefloat
-def str_offset():
+def str_gc_load(TYPE, buf, offset):
base_ofs = (llmemory.offsetof(STR, 'chars') +
llmemory.itemoffsetof(STR.chars, 0))
scale_factor = llmemory.sizeof(lltype.Char)
- return base_ofs, scale_factor
+ lls = llstr(buf)
+ return llop.gc_load_indexed(TYPE, lls, offset,
+ scale_factor, base_ofs)
class BaseLLOpTest(object):
@@ -29,18 +31,11 @@
class TestDirect(BaseLLOpTest):
def gc_load_from_string(self, TYPE, buf, offset):
- base_ofs, scale_factor = str_offset()
- lls = llstr(buf)
- return llop.gc_load_indexed(TYPE, lls, offset,
- scale_factor, base_ofs)
-
+ return str_gc_load(TYPE, buf, offset)
class TestRTyping(BaseLLOpTest, BaseRtypingTest):
def gc_load_from_string(self, TYPE, buf, offset):
def fn(offset):
- lls = llstr(buf)
- base_ofs, scale_factor = str_offset()
- return llop.gc_load_indexed(TYPE, lls, offset,
- scale_factor, base_ofs)
+ return str_gc_load(TYPE, buf, offset)
return self.interpret(fn, [offset])
diff --git a/rpython/translator/c/test/test_llop.py
b/rpython/translator/c/test/test_llop.py
--- a/rpython/translator/c/test/test_llop.py
+++ b/rpython/translator/c/test/test_llop.py
@@ -1,7 +1,5 @@
from rpython.rtyper.lltypesystem import lltype, llmemory, rffi
-from rpython.rtyper.lltypesystem.lloperation import llop
-from rpython.rtyper.annlowlevel import llstr
-from rpython.rtyper.test.test_llop import BaseLLOpTest, str_offset
+from rpython.rtyper.test.test_llop import BaseLLOpTest, str_gc_load
from rpython.translator.c.test.test_genc import compile
@@ -17,10 +15,7 @@
TARGET_TYPE = lltype.Signed
def llf(buf, offset):
- base_ofs, scale_factor = str_offset()
- lls = llstr(buf)
- x = llop.gc_load_indexed(TYPE, lls, offset,
- scale_factor, base_ofs)
+ x = str_gc_load(TYPE, buf, offset)
return lltype.cast_primitive(TARGET_TYPE, x)
fn = compile(llf, [str, int])
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit