Author: Armin Rigo <[email protected]>
Branch:
Changeset: r57800:4a5735975712
Date: 2012-10-06 11:41 +0200
http://bitbucket.org/pypy/pypy/changeset/4a5735975712/
Log: Optimization: avoids long longs when they are not needed.
diff --git a/pypy/module/_cffi_backend/ctypeptr.py
b/pypy/module/_cffi_backend/ctypeptr.py
--- a/pypy/module/_cffi_backend/ctypeptr.py
+++ b/pypy/module/_cffi_backend/ctypeptr.py
@@ -53,7 +53,7 @@
isinstance(ob.ctype, W_CTypePtrOrArray)):
value = ob._cdata
else:
- value = misc.as_unsigned_long_long(space, w_ob, strict=False)
+ value = misc.as_unsigned_long_nonstrict(space, w_ob)
value = rffi.cast(rffi.CCHARP, value)
return cdataobj.W_CData(space, value, self)
diff --git a/pypy/module/_cffi_backend/misc.py
b/pypy/module/_cffi_backend/misc.py
--- a/pypy/module/_cffi_backend/misc.py
+++ b/pypy/module/_cffi_backend/misc.py
@@ -1,7 +1,7 @@
from __future__ import with_statement
from pypy.interpreter.error import OperationError, operationerrfmt
from pypy.rpython.lltypesystem import lltype, llmemory, rffi
-from pypy.rlib.rarithmetic import r_ulonglong
+from pypy.rlib.rarithmetic import r_uint, r_ulonglong
from pypy.rlib.unroll import unrolling_iterable
from pypy.rlib.objectmodel import keepalive_until_here
from pypy.rlib import jit
@@ -181,6 +181,20 @@
neg_msg = "can't convert negative number to unsigned"
ovf_msg = "long too big to convert"
+def as_unsigned_long_nonstrict(space, w_ob):
+ # optimized version of as_unsigned_long_long(strict=False) if we're
+ # only interested in an Unsigned value
+ if space.is_w(space.type(w_ob), space.w_int): # shortcut
+ value = space.int_w(w_ob)
+ return r_uint(value)
+ try:
+ bigint = space.bigint_w(w_ob)
+ except OperationError, e:
+ if not e.match(space, space.w_TypeError):
+ raise
+ bigint = space.bigint_w(space.int(w_ob))
+ return bigint.uintmask()
+
# ____________________________________________________________
class _NotStandardObject(Exception):
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit