Re: [Python-Dev] Slot for __trunc__

2008-01-29 Thread Guido van Rossum
On Jan 29, 2008 11:34 AM, Raymond Hettinger [EMAIL PROTECTED] wrote:
 [GvR]
  I don't see why. __index__ has a slot because its
  primary use is to be called from C code, where slots
  add a slight performance advantage.
  __trunc__ doesn't get called from C AFAIK.

 I thought the __trunc__ method only gets called from
 the C code for the trunc() function which is currently
 implemented with PyObject_CallMethod(number, __trunc__, )
 instead of a fast call to a slot.

I see.

Well, it would bounce around a bit but it would never execute Python
byte codes. I don't see trunc() being all that performance critical.
The cost of adding a new slot is considerable -- for one, *all* type
objects become 4 (or 8) bytes longer.

-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)
___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Slot for __trunc__

2008-01-29 Thread Eric Smith
Raymond Hettinger wrote:
 [GvR]
 I don't see why. __index__ has a slot because its 
 primary use is to be called from C code, where slots
 add a slight performance advantage.
 __trunc__ doesn't get called from C AFAIK. 
 
 I thought the __trunc__ method only gets called from 
 the C code for the trunc() function which is currently
 implemented with PyObject_CallMethod(number, __trunc__, )
 instead of a fast call to a slot.

And if __trunc__ qualifies, what about __format__, which is similar? 
I'm not pushing for it, I just wonder how the decision is made.

Eric.
___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Slot for __trunc__

2008-01-29 Thread Guido van Rossum
I don't see why. __index__ has a slot because its primary use is to be
called from C code, where slots add a slight performance advantage.
__trunc__ doesn't get called from C AFAIK.

On Jan 29, 2008 11:04 AM, Raymond Hettinger [EMAIL PROTECTED] wrote:
 Should the implementation of __trunc__ have its own slot like we have for 
 nb_index?

 Raymond


 ---
 [EMAIL PROTECTED] ~/py26/Objects $ grep __trunc__ *.c
 floatobject.c:  {__trunc__,   (PyCFunction)float_trunc, METH_NOARGS,
 intobject.c:{__trunc__,   (PyCFunction)int_int,   METH_NOARGS,
 longobject.c:   {__trunc__,   (PyCFunction)long_long, METH_NOARGS,
 ___
 Python-Dev mailing list
 Python-Dev@python.org
 http://mail.python.org/mailman/listinfo/python-dev
 Unsubscribe: 
 http://mail.python.org/mailman/options/python-dev/guido%40python.org




-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)
___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


[Python-Dev] Slot for __trunc__

2008-01-29 Thread Raymond Hettinger
Should the implementation of __trunc__ have its own slot like we have for 
nb_index?

Raymond


---
[EMAIL PROTECTED] ~/py26/Objects $ grep __trunc__ *.c
floatobject.c:  {__trunc__,   (PyCFunction)float_trunc, METH_NOARGS,
intobject.c:{__trunc__,   (PyCFunction)int_int,   METH_NOARGS,
longobject.c:   {__trunc__,   (PyCFunction)long_long, METH_NOARGS,
___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Slot for __trunc__

2008-01-29 Thread Raymond Hettinger
[GvR]
 I don't see why. __index__ has a slot because its 
 primary use is to be called from C code, where slots
 add a slight performance advantage.
 __trunc__ doesn't get called from C AFAIK. 

I thought the __trunc__ method only gets called from 
the C code for the trunc() function which is currently
implemented with PyObject_CallMethod(number, __trunc__, )
instead of a fast call to a slot.


Raymond
___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com