Is 'everything' a refrence or isn't it?

David Murmann david.murmann at rwth-aachen.de
Thu Jan 5 07:35:43 EST 2006


Ich schrieb:
> but i think python does
> 
>  if (i == &_i2)
> 
> because there is only one integer object holding the value 2, so
> it is sufficient to compare the addresses (i'm not sure about this,
> perhaps someone smarter can clarify?).

well, as far as i can see the relevant function is 

static int
int_compare(PyIntObject *v, PyIntObject *w)
{
	register long i = v->ob_ival;
	register long j = w->ob_ival;
	return (i < j) ? -1 : (i > j) ? 1 : 0;
}

in Objects/intobject.c, which does compare by value. so, this is
either special-cased elsewhere or not optimized (should/can it be?).

--
David.



More information about the Python-list mailing list