Hi Andy,
If you have a patch (which it certainly looks like you do ;) I
recommend filing an issue for it:
http://code.google.com/p/googleappengine/issues/list
Happy coding,
Jeff
On Oct 15, 6:03 am, Andy Freeman <[EMAIL PROTECTED]> wrote:
> "not in" does the break, and since it's built-in, is faster than the
> user loop. More important, it's more clear what's going on.
>
> sets should be smaller and faster than dicts, and are definitely more
> clear.
>
> Yes, some things that have == tests can't be used as set members. The
> code that sets self.choices can decide whether to use a set using
> something like:
>
> google/appengine/db/__init__.py line 333 with
> try:
> self.choices = set(value)
> except:
> self.choices = value
>
> Note that both "not in" and the current loop work with both sets and
> lists.
>
> On Oct 14, 3:32 pm, djidjadji <[EMAIL PROTECTED]> wrote:
>
> > Why not break when a match is found
> > if self.choices:
> > match = False
> > for choice in self.choices:
> > if choice == value:
> > match = True
> > break
> > if not match:
> > raise BadValueError('Property %s is %r; must be one of %r' %
> > (self.name, value,self.choices))
>
> > Maybe faster to make self.choices a dictionary.
> > The keys are in a hash table and that is faster then linear searching
>
> > self.choices = { choice1:True, choice2:True }
> > ......
> > if self.choices:
> > if not self.choices.get(value):
> > raise BadValueError('Property %s is %r; must be one of %r' %
> > (self.name, value,self.choices))
>
> > 2008/10/13 Andy Freeman <[EMAIL PROTECTED]>:
>
> > > google/appengine/db/__init__.py starting at line 401 is:
> > > if self.choices:
> > > match = False
> > > for choice in self.choices:
> > > if choice == value:
> > > match = True
> > > if not match:
> > > raise BadValueError('Property %s is %r; must be one of %r' %
> > > (self.name, value,
> > > self.choices))
>
> > > It could be:
> > > if value not in (self.choices or (value,)):
> > > raise BadValueError('Property %s is %r; must be one of %r' %
> > > (self.name, value,
> > > self.choices))
>
> > > "not in" will stop when it finds a match and may be faster for each
> > > element checked.
>
> > > Note that making self.choices a set would make the "not in" test O(1).-
> > > Hide quoted text -
>
> > - Show quoted text -
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Google App Engine" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/google-appengine?hl=en
-~----------~----~----~----~------~----~------~--~---