On Sun, Jun 1, 2008 at 8:20 PM, Tim Chase <[EMAIL PROTECTED]> wrote: > > > * On a similar note, I can see a lot of places where you > > seem to be copies of lists (or sublists) - this is an > > expensive operation if you do it a lot, especially since > > most cases you could get the same effect by keeping the > > index values and slicing the original list as required. > > Handling for row[:aggregate_start] seems to be the worst > > culprit here. > > My understanding is that slicing a list produces a new list, > so I'm not sure this is a real gain. Each object in the > list is only held once (unless copy.deepcopy() is called) > and the new (sub)list merely contains references to those > object-ids, like any other python variable.
To my understanding, a slice isn't automatically a copy - it will be in most cases, but there are cases where the bytecode compiler will use the original list as an optimization. One example: >>> s = 'abc' >>> t = s[:] >>> s is t True >>> id(s) 3081872000L >>> id(t) 3081872000L I'm willing to be corrected here, but my understanding was that for loop iteration was one of those optimization cases. Either way, part of my original comment was driving at cleaning up the implementation code. I'm not convinced that having lots of variable names representing relatively simple slices of an original list is necessary for code clarity - I would contend that: for x in intial_list[a:b]: do stuff is easier to read than: sub_list = initial_list[a:b] for x in sub_list: do stuff If the former case is an optimization, that makes the argument even more convincing, but even if it isn't, I would argue that the cleanup would be worthwhile. > Yes, it would be nice if this worked because it's logically > true...except that it doesn't work (at least in Postgres and > MS-SQL Server): Aw...crap. You are, of course, completely correct. I've been spending too much time in MySQL of late, and I forgot that this was an eccentricity of MySQL. Thanks for slapping me upside the head when I needed it :-) Yours, Russ Magee %-) --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to django-developers@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-developers?hl=en -~----------~----~----~----~------~----~------~--~---