is implemented with id ?

Hans Mulder hansmu at xs4all.nl
Sun Nov 4 11:13:07 CET 2012


On 4/11/12 06:09:24, Aahz wrote:
> In article <mailman.3250.1351999198.27098.python-list at python.org>,
> Chris Angelico  <rosuav at gmail.com> wrote:
>> On Sun, Nov 4, 2012 at 2:10 PM, Steven D'Aprano
>> <steve+comp.lang.python at pearwood.info> wrote:
>>>
>>> /* Shortcut for empty or interned objects */
>>> if (v == u) {
>>>     Py_DECREF(u);
>>>     Py_DECREF(v);
>>>     return 0;
>>> }
>>> result = unicode_compare(u, v);
>>>
>>> where v and u are pointers to the unicode object.
>>
>> There's a shortcut if they're the same. There's no shortcut if they're
>> both interned and have different pointers, which is a guarantee that
>> they're distinct strings. They'll still be compared char-for-char
>> until there's a difference.
> 
> Without looking at the code, I'm pretty sure there's a hash check first.

In 3.3, there is no such check.

It was recently proposed on python-dev to add such a check,
but AFAIK, no action was taken.

-- HansM




More information about the Python-list mailing list