for copying arrays and/or converting iterables like 'arguments' to
arrays,

// arguments -> array
newArray = Array.slice( arguments );

// copy a->b
copy = Array.slice( original );

--- provides a small increase in speed for a variety of array
operations contained in prototype

also for array iteration:

// declare var outside of loop -- slightly faster...
var i;
for( i=100000; i--; ){
     //  execute code here
}

--- in cases where order is not relevant, this method benchmarks
faster than any other in all browsers tested ( *safari/mac not
tested )

also, for generating unique arrays:

function uniqueArray( array ){
   var uniqueHash = {}, unique=[], i;
   for( i=array.length; i--; ){
      if( !uniqueHash[ a[i] ]){
         unique.push( array[i] );
         uniqueHash[ a[i] ] = true;
      }
   }
   return unique;
}

and is there any reason not to use String.replace([regexp], function()
{} ) for a large part of the functions implemented by iterating
through arrays?  this can be blazingly fast even for complicated regex
as long as they are precompiled, and the code is far more readable and
compact (i.e. camelization, templating, etc etc )

there are some other much more significant optimizations which might
be worthwhile and i would appreciate feedback once i clean up the code
a bit more...

and --- a big kudos to the prototype team -- discovering prototype way
back when completely changed the way i code javascript - thanks.

ss


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Prototype: Core" group.
To post to this group, send email to prototype-core@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/prototype-core?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to