Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #32711
| References | (4 earlier) <k73s18$5b4$1@panix5.panix.com> <50959154$0$6880$e4fe514c@news2.news.xs4all.nl> <50959827$0$29967$c3e8da3$5496439d@news.astraweb.com> <CAPTjJmpCV4AZ9PGT6pMs2qzw4mm5F3Nb8ZstV4zD1Y++tgbe4g@mail.gmail.com> <CAHVvXxS8DaH9AGzJkFtgQnUeewP2QNEoXdVqLDh0yWX6bSr1pQ@mail.gmail.com> |
|---|---|
| Date | 2012-11-04 12:22 +1100 |
| Subject | Re: is implemented with id ? |
| From | Chris Angelico <rosuav@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.3249.1351992140.27098.python-list@python.org> (permalink) |
On Sun, Nov 4, 2012 at 12:14 PM, Oscar Benjamin <oscar.j.benjamin@gmail.com> wrote: > On 3 November 2012 22:50, Chris Angelico <rosuav@gmail.com> wrote: >> This one I haven't checked the source for, but ISTR discussions on >> this list about comparison of two unequal interned strings not being >> optimized, so they'll end up being compared char-for-char. Using 'is' >> guarantees that the check stops with identity. This may or may not be >> significant, and as you say, defending against an uninterned string >> slipping through is potentially critical. > > The source is here (and it shows what you suggest): > http://hg.python.org/cpython/file/6c639a1ff53d/Objects/unicodeobject.c#l6128 > > Comparing strings char for char is really not that big a deal though. > This has been discussed before: you don't need to compare very many > characters to conclude that strings are unequal (if I remember > correctly you were part of that discussion). Yes, and a quite wide-ranging discussion it was too! What color did we end up whitewashing that bikeshed? *whistles innocently* > I can imagine cases where I might consider using intern on lots of > strings to speed up comparisons but I would have to be involved in > some seriously heavy and obscure string processing problem before I > considered using 'is' to compare those interned strings. That is > confusing to anyone who reads the code, prone to bugs and unlikely to > achieve the desired outcome of speeding things up (noticeably). Good point. It's still true that 'is' will be faster, it's just not worth it. ChrisA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
is implemented with id ? Franck Ditter <franck@ditter.org> - 2012-09-05 08:30 +0200
Re: is implemented with id ? Benjamin Kaplan <benjamin.kaplan@case.edu> - 2012-09-04 23:40 -0700
Re: is implemented with id ? Franck Ditter <franck@ditter.org> - 2012-09-05 15:19 +0200
Re: is implemented with id ? Hans Mulder <hansmu@xs4all.nl> - 2012-09-05 15:48 +0200
Re: is implemented with id ? aahz@pythoncraft.com (Aahz) - 2012-11-03 12:41 -0700
Re: is implemented with id ? Hans Mulder <hansmu@xs4all.nl> - 2012-11-03 22:49 +0100
Re: is implemented with id ? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-11-03 22:18 +0000
Re: is implemented with id ? Chris Angelico <rosuav@gmail.com> - 2012-11-04 09:50 +1100
Re: is implemented with id ? Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2012-11-04 01:14 +0000
Re: is implemented with id ? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-11-04 03:10 +0000
Re: is implemented with id ? Chris Angelico <rosuav@gmail.com> - 2012-11-04 14:19 +1100
Re: is implemented with id ? aahz@pythoncraft.com (Aahz) - 2012-11-03 22:09 -0700
Re: is implemented with id ? Hans Mulder <hansmu@xs4all.nl> - 2012-11-04 11:13 +0100
Re: is implemented with id ? Chris Angelico <rosuav@gmail.com> - 2012-11-04 12:22 +1100
Re: is implemented with id ? aahz@pythoncraft.com (Aahz) - 2012-11-03 22:08 -0700
Re: is implemented with id ? Roy Smith <roy@panix.com> - 2012-11-03 18:41 -0400
Re: is implemented with id ? aahz@pythoncraft.com (Aahz) - 2012-11-03 22:12 -0700
Re: is implemented with id ? Dave Angel <d@davea.name> - 2012-09-05 10:00 -0400
Re: is implemented with id ? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-09-05 14:41 +0000
Re: is implemented with id ? Dave Angel <d@davea.name> - 2012-09-05 11:09 -0400
Re: is implemented with id ? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-09-05 15:36 +0000
Re: is implemented with id ? Hans Mulder <hansmu@xs4all.nl> - 2012-09-05 18:47 +0200
Re: is implemented with id ? Dave Angel <d@davea.name> - 2012-09-05 13:19 -0400
Re: is implemented with id ? Terry Reedy <tjreedy@udel.edu> - 2012-09-05 14:31 -0400
Re: is implemented with id ? Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2012-09-05 22:08 -0400
Re: is implemented with id ? Duncan Booth <duncan.booth@invalid.invalid> - 2012-09-06 09:34 +0000
Re: is implemented with id ? Chris Angelico <rosuav@gmail.com> - 2012-09-06 19:50 +1000
Re: is implemented with id ? 88888 Dihedral <dihedral88888@googlemail.com> - 2012-11-04 01:33 -0700
Re: is implemented with id ? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-09-05 09:14 +0000
Re: is implemented with id ? Ramchandra Apte <maniandram01@gmail.com> - 2012-09-05 05:48 -0700
Re: is implemented with id ? Dave Angel <d@davea.name> - 2012-09-05 09:46 -0400
Re: is implemented with id ? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-09-05 14:13 +0000
Re: is implemented with id ? Ian Kelly <ian.g.kelly@gmail.com> - 2012-09-05 11:08 -0600
Re: is implemented with id ? Chris Angelico <rosuav@gmail.com> - 2012-09-06 19:07 +1000
Re: is implemented with id ? Terry Reedy <tjreedy@udel.edu> - 2012-09-05 14:27 -0400
Re: is implemented with id ? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-09-06 06:44 +0000
Re: is implemented with id ? Ramchandra Apte <maniandram01@gmail.com> - 2012-09-06 01:24 -0700
Re: is implemented with id ? Roy Smith <roy@panix.com> - 2012-09-06 08:16 -0400
Re: is implemented with id ? Ramchandra Apte <maniandram01@gmail.com> - 2012-09-06 06:30 -0700
Re: is implemented with id ? Dave Angel <d@davea.name> - 2012-09-05 14:40 -0400
csiph-web