Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!weretis.net!feeder4.news.weretis.net!ecngs!feeder2.ecngs.de!newsfeeder.ewetel.de!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.040 X-Spam-Evidence: '*H*': 0.92; '*S*': 0.00; 'strings.': 0.07; 'pointers': 0.09; 'shortcut': 0.09; 'distinct': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'pointers,': 0.16; 'v);': 0.16; 'wrote:': 0.17; 'unicode': 0.17; 'received:209.85.214.174': 0.21; 'object.': 0.22; 'header:In- Reply-To:1': 0.25; 'message-id:@mail.gmail.com': 0.27; "d'aprano": 0.29; 'steven': 0.29; "they'll": 0.29; 'objects': 0.29; 'probably': 0.29; 'subject: ?': 0.30; 'point': 0.31; 'to:addr :python-list': 0.33; 'received:google.com': 0.34; 'compared': 0.35; 'faster': 0.35; 'nov': 0.35; 'same.': 0.35; 'pm,': 0.35; 'received:209.85': 0.35; 'except': 0.36; 'but': 0.36; 'subject:with': 0.36; 'enough': 0.36; 'received:209': 0.37; 'subject:: ': 0.38; 'performance': 0.39; 'to:addr:python.org': 0.39; 'received:209.85.214': 0.39; 'where': 0.40; 'header:Received:5': 0.40; 'skip:u 10': 0.60; 'safe': 0.63; 'different': 0.63; 'difference.': 0.84; 'penalty': 0.84; 'technically': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=UAkwQtCHXNmbOgbQ4DKL82oMSjRpppyiykeyn4yFqg4=; b=zx3TL6qDu5JFYGxtVg9DabfcK2Vyr5r9b34q2xwBFW5BQR16z1ITxDDzGoY7H0iUgG jM8cqktfOl7UqxObtwtqa3ewx1GFdbPeHRW0p3lZowI5kouxNte3uFxdFknKfZDOZAAT Eq+pNWAQD1yja3YSh+qOSA1dBCDKqwjX+jXm2nnYcNif/dJIJBa1E3Its81vcMjbvfIx gQMjf/8+r3Z9ba8jan3g61GKz1rPyp6EShyZ6XdYDiYXXYicmtYk1poF0h4oE+is5dQ3 au9EWBFAv+g4hh/WxdsK+HP6HBLIX7puTOzUIq0N9wsd2nauWw2xiLoLdB+T8n+8Jsvp ZCXg== MIME-Version: 1.0 In-Reply-To: <5095dca0$0$29967$c3e8da3$5496439d@news.astraweb.com> References: <50475822$0$6867$e4fe514c@news2.news.xs4all.nl> <50959154$0$6880$e4fe514c@news2.news.xs4all.nl> <50959827$0$29967$c3e8da3$5496439d@news.astraweb.com> <5095dca0$0$29967$c3e8da3$5496439d@news.astraweb.com> Date: Sun, 4 Nov 2012 14:19:55 +1100 Subject: Re: is implemented with id ? From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 24 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1351999198 news.xs4all.nl 6922 [2001:888:2000:d::a6]:49808 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:32715 On Sun, Nov 4, 2012 at 2:10 PM, Steven D'Aprano 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. But it probably isn't enough of a performance penalty to be concerned with. It's enough to technically prove the point that 'is' is faster than '==' and is still safe if both strings are interned; it's not enough to make 'is' better than '==', except in very specific situations. ChrisA