Making "inline calling" would be avoided if not really necessary. Is the speed difference of two solutions relevant at this point? However, I am sure that John will consider this optimization too if needed.
On Mar 1, 8:01 pm, ricardobeat <ricardob...@gmail.com> wrote: > We can preserve the index without resorting to get (and without > affecting performance) by using a ternary: > > jQuery.fn.eq = function( i ) { > return this.pushStack( this[i<0 ? i+this.length : i], 'eq', i ) > > } > > cheers, > - ricardo > > On Feb 28, 8:42 pm, Robert Katić <robert.ka...@gmail.com> wrote: > > > An slightly slower but more robust solution would be: > > > eq: function( i ) { > > return this.pushStack( this.get(i), 'eq', i ) > > > } > > > The main difference is that the ret.selector would preserve the > > initial index (relative if negative). > > > On Feb 28, 9:44 pm, Robert Katić <robert.ka...@gmail.com> wrote: > > > > If this solution seems ok, I would update the > > > tickethttp://dev.jquery.com/ticket/4188. > > > > On Feb 28, 8:50 pm, ricardobeat <ricardob...@gmail.com> wrote: > > > > > Nice catch, that makes sense. Added it to the test page, it has no > > > > significant impact on performance. > > > > > cheers, > > > > - ricardo > > > > > On Feb 27, 7:27 pm, Robert Katić <robert.ka...@gmail.com> wrote: > > > > > > Since .get(-1) will be supported, eq(-1) would be supported too (?). > > > > > > So your implementation needs some extra code: > > > > > > eq: function( i ) { > > > > > if ( i < 0 ) > > > > > i += this.length; > > > > > return this.pushStack( this[i], 'eq', i ) > > > > > > } > > > > > > However this solution would be still faster then the one > > > > > onhttp://dev.jquery.com/ticket/4188, I suppose. > > > > > > On Feb 26, 11:02 pm, ricardobeat <ricardob...@gmail.com> wrote: > > > > > > > Right, thanks! > > > > > > > Using pushStack seems ok, it's still chainable and keeps the > > > > > > selector > > > > > > state, while still being at least twice faster. > > > > > > >http://dev.jquery.com/ticket/4262http://jquery.nodnod.net/cases/177/run > > > > > > > cheers, > > > > > > - ricardo > > > > > > > On Feb 26, 11:28 am, John Resig <jere...@gmail.com> wrote: > > > > > > > > Well, first I would argue that the two are not equivalent. > > > > > > > > $($(...)[x]) doesn't maintain the stack. You can no longer do: > > > > > > > $(...).eq(1).addClass("test").end().appendTo("#foo"); > > > > > > > $($(...)[x]) doesn't maintain the internal selector state for > > > > > > > plugins. > > > > > > > For example if you checked $(...).eq(1).selector you'd see: > > > > > > > ".slice(1, > > > > > > > 2)" > > > > > > > > So, with that in mind, if there were ways to maintain that > > > > > > > functionality and still get a performance speed-up, I'd > > > > > > > definitely be > > > > > > > open to it. > > > > > > > > --John > > > > > > > > On Wed, Feb 25, 2009 at 11:41 PM, Ricardo Tomasi > > > > > > > <ricardob...@gmail.com> wrote: > > > > > > > > > Creating two jQuery objects + a lookup $( $(...)[x] ) is faster > > > > > > > > than a > > > > > > > > simple $(...).eq(x). That doesn't make much sense. > > > > > > > > > Currently the eq function looks like this: > > > > > > > > eq: function( i ) { > > > > > > > > return this.slice( i, +i + 1 ); > > > > > > > > }, > > > > > > > > > Are there any downsides to changing it to this (object unique > > > > > > > > IDs, > > > > > > > > chaining)? > > > > > > > > > eq: function( i ) { > > > > > > > > return jQuery(this[i]); > > > > > > > > }, > > > > > > > > > That offers a 25% to 40% speed improvement across all browsers. > > > > > > > >http://jquery.nodnod.net/cases/177 > > > > > > > > > cheers, > > > > > > > > - ricardo > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "jQuery Development" group. To post to this group, send email to jquery-dev@googlegroups.com To unsubscribe from this group, send email to jquery-dev+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/jquery-dev?hl=en -~----------~----~----~----~------~----~------~--~---