Mike Bayer <[email protected]> writes:
> throwing an isinstance() right into the otherwise no-latency __getitem__
> (the pure python version) there is making me think this may be better as a
> key fallback, so the expense is limited just to the negative integer case
> (or another idea, the negative int keys could be pre-populated the same way
> the positive ones are). what do you think?
This is exactly what made me wonder about the right location of the "adaption"
logic.
I will rewrite the tweak, but can you clear your indication: is it something
like
def __getitem__(self, key):
try:
processor, obj, index = self._keymap[key]
except KeyError:
if isinstance(key, util.int_types) and key < 0:
positive_key = key + len(self)
try:
processor, obj, index = self._keymap[positive_key]
except KeyError:
processor, obj, index = self._parent._key_fallback(key)
else:
processor, obj, index = self._parent._key_fallback(key)
or instead about moving the logic enterely within the _key_fallback() method,
leaving the __getitem__() one exactly as it is/was? The former is somewhat
faster, at the cost of a tiny code dup, because there isn't any extra lookup
and function call, while the latter has the advantage that the C would remain
untouched (but I'd make a different commit removing the redundant index
computation under Py2).
Thank you,
ciao, lele.
--
nickname: Lele Gaifax | Quando vivrò di quello che ho pensato ieri
real: Emanuele Gaifas | comincerò ad aver paura di chi mi copia.
[email protected] | -- Fortunato Depero, 1929.
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.