[Patches] [ python-Patches-1548082 ] "if x in setliteral" peepholer optimization

SourceForge.net noreply at sourceforge.net
Tue Aug 29 23:57:22 CEST 2006


Patches item #1548082, was opened at 2006-08-28 13:38
Message generated for change (Settings changed) made by gvanrossum
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1548082&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Core (C code)
Group: Python 3000
>Status: Closed
>Resolution: Rejected
Priority: 5
Submitted By: Georg Brandl (gbrandl)
Assigned to: Guido van Rossum (gvanrossum)
Summary: "if x in setliteral" peepholer optimization

Initial Comment:
Like "for x in tuple_or_list", this patch rewrites "for
x in set" to use a constant frozenset.

----------------------------------------------------------------------

>Comment By: Guido van Rossum (gvanrossum)
Date: 2006-08-29 17:57

Message:
Logged In: YES 
user_id=6380

Let me reject this as a waste of time right now.

See my post "Premature optimization and all that" in the
py3k list.

----------------------------------------------------------------------

Comment By: Raymond Hettinger (rhettinger)
Date: 2006-08-29 17:26

Message:
Logged In: YES 
user_id=80475

This implementation too simplistic, you need to use a
subclass of frozenset that overrides the __contains__()
method to return False when the argument is not hashable. 
Otherwise, you end-up with a semantic change for:

   x = {}
   if x in [1,2,3]:
       print 'Not Found'

----------------------------------------------------------------------

Comment By: Georg Brandl (gbrandl)
Date: 2006-08-29 15:08

Message:
Logged In: YES 
user_id=849994

Argh. Like in the py3k mail, I confusedly interchanged "for
x in set" and "if x in set".

if x in [1,2,3] does get special treatment, and optimizing
the "in" test does make sense.

----------------------------------------------------------------------

Comment By: Guido van Rossum (gvanrossum)
Date: 2006-08-29 14:24

Message:
Logged In: YES 
user_id=6380

Um, "for x in [1,2,3]" doesn't get any treatment. What would
be the point of writing "for x in {1,2,3}" anyway?

I'd rather reject this as premature optimization.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1548082&group_id=5470


More information about the Patches mailing list