Slow script errors caused by jQuery.fn.extend.find
I have a form that is dynamically constructed using JSP. It creates a spreadsheet-like table where the user associates a row with a column by clicking a radio button. It's possible that there may be up to 400 rows and 50 columns, making the table unwieldy. (For example, the row and column headings disappear when the user scrolls down or to the right.) Our solution was to create a tooltip on each radio button to identify the row and the column of that radio button. It works great for a small number of rows and columns. But when we run it with the larger numbers, we get slow script errors. This block of code in the find section of jQuery.fn.extend is where the errors occur:
if ( i > 0 ) {
// Make sure that the results are unique
for ( var n = length; n < ret.length; n++ ) {
for ( var r = 0; r < length; r++ ) {
if ( ret[r] === ret[n] ) {
ret.splice(n--, 1);
break;
}
}
}
}
Obviously, this code is searching elements, one at a time, looking for duplicates. Can this code be re-written to do a binary search on a sorted set? I'm new to jquery, so I don't know if there are functions available to do that. For now, I've simply commented out this code because no duplicates were ever found.
I've attached the html file generated by the JSP. It contains 200 rows and 50 columns, and causes slow script errors if I don't have the code above commented out. I'm using jquery-1.5.js, jquery.ui 1.8.9, and jquery tooltip plugin 1.3.
Thanks for your help.