Thank you for your comments.  Writing these methods is like creating and
solving little puzzles.  Much fun!


> > // Remove all elements from Array
> > Array.prototype.clear = function() {
> >     this.length = 0;
> > };
> 
> This function scares me to death.

According to the official Flash documentation

"Note: If you assign a value to the length property that is shorter than
the existing length, the array will be truncated."  


> Which is faster, iterating over an array of size N once and checking
> for elements that are either null or undefined in a single pass, or
> iterating over an array of size N checking for nulls and then
> iterating again over an array of size N-x and checking for the
> undefineds?

You're right. I've updated my script.


> You do this sort of thing in several of your functions and I think you
> _might_ be able to squeeze a bit of theoretical speed out of things by
> 
> if obj is an array
>    loop checking for array equality
> else
>    loop checking for value equality
> 
> In stead of
> 
> loop over the entire array
>   check value equality
>   if obj is an array
>     check array equality

Good catch.  I've added an or to the first if in the eql method to
verify the argument passed is an array and have changed the other
methods so instanceof checks happen as infrequently as possible.  I've
also modified all the places that I run these if statements to minimize
instanceof checks.


> Also, what's the performance hit for splice()? I know it's bad in some
> languages. Would it be potentially faster to build a new array in
> stead of re-splicing the old one? I guess it depends on the length of
> the array as compared to the number of elements being removed. What is
> the threshold where one becomes preferrable to the other?

Splice is slow.  Creating a new array is preferable but reassigning
another array to 'this' doesn't work inside a prototype because an
instance can't delete or replace itself.  But, clearing the array and
reiterating is a better overall strategy than splicing.  I wrote a pair
of methods to help.

Director has a method 'duplicate' which is missing from Flash.  I have
added that and its sister method, 'replicate' to my extension.
duplicate makes a copy of 'this' in a new array and returns it,
replicate turns 'this' into a copy of another array.


> > filter
> I love this one. I use it absolutely all the time in other languages.

RecordSet has it, but Arrays do not.  About time, too.
_______________________________________________
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

Reply via email to