Garrett Smith wrote:
> Thomas 'PointedEars' Lahn wrote:
>> David Mark wrote:
>>
>>> Thomas 'PointedEars' Lahn wrote:
>>>> David Mark wrote:
>>>>> Scott Sauyet wrote:
>>>>>> var photos = [], captions = [];
>>>>>> for (var i = 0, len = library.length; i < len; i++) {
>>>>>> photos.push(library[i]["img"]);
>>>>>> captions.push(library[i]["caption"]);
>>>>>> }
>>>>> var photos = [], captions = [];
>>>>> photos.length = captions.length = library.length;
>>>>> for (var i = 0, len = library.length; i--
{
>> ^^^^^ ^^^
>>>> No 
>>> No? Perhaps you meant you could improve on it?
>>
>> If "to improve" means "let it do anything useful", then yes. Long
>> night?
Yes. Typo. Was supposed to be
for (var i = library.length; i--
.... and I didn't notice Thomas fixed that either. Bleary-eyed after
reading a bunch of (typically) horrible JS overnight. Why do the worst
programmers in the world write seemingly all of the "major" JS. It's
just not sustainable, so I think we'll all end up programming ES in
Flash or the like.
>>
>>>>> photos[i] = library[i]["img"];
>>>>> captions[i] = library[i]["caption"];
>>>>> }
>>>> var
>>>> photos = [],
>>>> captions = [],
>>>> len = library.length;
>>>>
>>>> photos.length = captions.length = len;
>>>>
>>>> for (var i = len; i--
>>>> {
>>>> var o = library[i];
>>>> photos[i] = o.img;
>>>> captions[i] = o.caption;
>>>> }
>>> Yes, the start's a bit nicer (library length). I don't know if that
>>> assignment to o will help though. You only saved two lookups. Not
>>> worth worrying about it at this point.
>>
>> Benchmarks suggest it would be about 20% faster in TraceMonkey 1.9.1.6.
>>
> Setting the length will avoid step 10 in array [[Put]], so should be
> fastest. IE versions may benefit even more from this.
But, as Thomas noted, it will be set (for good) the first time as we are
going backwards.