Very nice, Matt. This serialize method is way faster if the select
element is not a "multiple" select which I assume is how you
benchmarked it.  When the select is a multiple-select then I see
basically the same performance with the for-loop impl posted on the
other thread.  I did a quick test and got the following results:

muliple-select element w/500 options:
new 'each' impl (ave of 10 tests): 113ms
for-loop impl (ave of 10 tests): 104ms

single-select element w/500 options:
new 'each' impl (ave of 10 tests): 7ms
for-loop impl (ave of 10 tests): 103ms

So I think this new serialize method is pretty damn good!  Is there
*anyone* out there that cares about the semantic ordering of the
posted values?  Personally, I do not, and I definitely would like to
have only a single serialize method.  Maybe the semantic version could
be left as a separate plugin for anyone that needs that capability.  I
vote for updating the form plugin with this new version.

Mike



On 10/3/06, Matt Grimm <[EMAIL PROTECTED]> wrote:
> Hello,
>
> I've put together a fast form serializer function that I'm hoping can
> get some review from the list for completeness, bugs, a better name,
> etc. A previous thread revealed quite a performance issue with the form
> plugin's existing serialize function when operating on a form with a
> large number of elements. My plugin sacrifices semantic order for wicked
> speed. I have a test form with a select menu containing 500 options --
> with the current serializer, it takes around 5 full seconds to do the
> job, and with mine, it takes about 50 ms. Any feedback would be much
> appreciated, including whether you think this should be included with
> the form plugin distribution.
>
> Since this isn't a plugin, I'm just going to include the source in this
> message -- please let me know if there's a better (i.e., more polite)
> way to do this.
>
> Thanks!
>
> m.
>
> ---
>
> $.fn.fastSerialize = function() {
>     var a = [];
>     var f = ['INPUT', 'TEXTAREA', 'SELECT', 'BUTTON'];
>
>     $(f.join(','), this).each(function() {
>         var n = this.name || this.id;
>         var t = this.type;
>
>         if (!n || this.disabled || t == 'reset' ||
>            (t == 'checkbox' || t == 'radio') && !this.checked ||
>            (t == 'submit' || t == 'image' || t == 'button') &&
> this.form.clicked != this ||
>            this.tagName == 'SELECT' && this.selectedIndex == -1)
>             return;
>
>         if (t == 'image' && this.form.clicked_x)
>             return a.push(
>                 {name: n+'_x', value: this.form.clicked_x},
>                 {name: n+'_y', value: this.form.clicked_y}
>             );
>
>         if (t == 'select-multiple') {
>             $('option', this).each( function() {
>                 if (this.selected)
>                     a.push({name: n, value: this.value ||
> $(this).text()});
>             });
>             return;
>         }
>
>         a.push({name: n, value: this.value});
>     });
>
>     return a;
> };
>
> _______________________________________________
> jQuery mailing list
> discuss@jquery.com
> http://jquery.com/discuss/
>

_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/

Reply via email to