[pypy-svn] r12011 - pypy/dist/pypy/objspace/std
tismer at codespeak.net
tismer at codespeak.net
Fri May 6 13:58:42 CEST 2005
Author: tismer
Date: Fri May 6 13:58:42 2005
New Revision: 12011
Modified:
pypy/dist/pypy/objspace/std/floatobject.py
pypy/dist/pypy/objspace/std/intobject.py
pypy/dist/pypy/objspace/std/longobject.py
Log:
a few small (but hard to find) changes avoid
pulling the whole interpreter in on basic operations.
Especially space.is_true should be avoided
and space.is_w should work directly.
Modified: pypy/dist/pypy/objspace/std/floatobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/floatobject.py (original)
+++ pypy/dist/pypy/objspace/std/floatobject.py Fri May 6 13:58:42 2005
@@ -42,7 +42,10 @@
# a derived float object, where it should return
# an exact one.
def float__Float(space, w_float1):
- if space.is_true(space.is_(space.type(w_float1), space.w_float)):
+ # don't trigger a descr operation.
+ # XXX let's consider to change space.is_ to plain bool
+ #if space.is_true(space.is_(space.type(w_float1), space.w_float)):
+ if space.w_True is space.is_(space.type(w_float1), space.w_float):
return w_float1
a = w_float1.floatval
return W_FloatObject(space, a)
@@ -157,9 +160,14 @@
truediv__Float_Float = div__Float_Float
+# avoid space.getitem for a basic operation
+##def floordiv__Float_Float(space, w_float1, w_float2):
+## w_t = divmod__Float_Float(space, w_float1, w_float2)
+## return space.getitem(w_t, space.wrap(0))
+
def floordiv__Float_Float(space, w_float1, w_float2):
- w_t = divmod__Float_Float(space, w_float1, w_float2)
- return space.getitem(w_t, space.wrap(0))
+ w_div, w_mod = _divmod_w(space, w_float1, w_float2)
+ return w_div
def mod__Float_Float(space, w_float1, w_float2):
x = w_float1.floatval
@@ -176,7 +184,7 @@
return W_FloatObject(space, mod)
-def divmod__Float_Float(space, w_float1, w_float2):
+def _divmod_w(space, w_float1, w_float2):
x = w_float1.floatval
y = w_float2.floatval
if y == 0.0:
@@ -203,8 +211,10 @@
except FloatingPointError:
raise FailedToImplement(space.w_FloatingPointError, space.wrap("float division"))
- return space.newtuple([W_FloatObject(space, floordiv),
- W_FloatObject(space, mod)])
+ return [W_FloatObject(space, floordiv), W_FloatObject(space, mod)]
+
+def divmod__Float_Float(space, w_float1, w_float2):
+ return space.newtuple(_divmod_w(space, w_float1, w_float2))
def pow__Float_Float_ANY(space, w_float1, w_float2, thirdArg):
if not space.is_w(thirdArg, space.w_None):
Modified: pypy/dist/pypy/objspace/std/intobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/intobject.py (original)
+++ pypy/dist/pypy/objspace/std/intobject.py Fri May 6 13:58:42 2005
@@ -174,18 +174,12 @@
return W_IntObject(space, z)
def _truediv(space, w_int1, w_int2):
- x = w_int1.intval
- y = w_int2.intval
- try:
- z = ovfcheck(x // y)
- except ZeroDivisionError:
- raise OperationError(space.w_ZeroDivisionError,
- space.wrap("integer division by zero"))
- except OverflowError:
- return space.div(space.newfloat(float(x)), w_int2)
- if x % y != 0: # gives a float
- return space.div(space.newfloat(float(x)), w_int2)
- return W_IntObject(space, z)
+ # XXX how to do delegation to float elegantly?
+ # avoiding a general space.div operation which pulls
+ # the whole interpreter in.
+ # Instead, we delegate to long for now.
+ raise FailedToImplement(space.w_TypeError,
+ space.wrap("integer division"))
def mod__Int_Int(space, w_int1, w_int2):
x = w_int1.intval
@@ -396,7 +390,10 @@
# a derived integer object, where it should return
# an exact one.
def int__Int(space, w_int1):
- if space.is_true(space.is_(space.type(w_int1), space.w_int)):
+ # don't trigger a descr operation.
+ # XXX let's consider to change space.is_ to plain bool
+ #if space.is_true(space.is_(space.type(w_int1), space.w_int)):
+ if space.w_True is space.is_(space.type(w_int1), space.w_int):
return w_int1
a = w_int1.intval
return W_IntObject(space, a)
Modified: pypy/dist/pypy/objspace/std/longobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/longobject.py (original)
+++ pypy/dist/pypy/objspace/std/longobject.py Fri May 6 13:58:42 2005
@@ -103,7 +103,10 @@
# a derived long object, where it should return
# an exact one.
def long__Long(space, w_long1):
- if space.is_true(space.is_(space.type(w_long1), space.w_long)):
+ # don't trigger a descr operation.
+ # XXX let's consider to change space.is_ to plain bool
+ #if space.is_true(space.is_(space.type(w_long1), space.w_long)):
+ if space.w_True is space.is_(space.type(w_long1), space.w_long):
return w_long1
digits = w_long1.digits
sign = w_long1.sign
More information about the Pypy-commit
mailing list