Bug Tracker

Opened 10 years ago

Closed 9 years ago

#4720 closed enhancement (fixed)

Performance: Cache array methods for faster accessing

Reported by: fearphage Owned by:
Priority: minor Milestone: 1.4
Component: core Version: 1.3.2
Keywords: Cc:
Blocked by: Blocking:

Description

Array.prototype.slice appears 5 times in jQuery
Array.prototype.push appears 2 times in jQuery

There are several places where the cached value can be reused but are not as well.

These could be cached at the beginning along with window and undefined.

var window = this
    ,undefined
    ,push = Array.prototype.push
    ,slice = Array.prototype.slice

/* ... snip ... */

  if ( toString.call(array) === "[object Array]" ) {
    Array.prototype.push.apply( ret, array );
  }

/* ... snip ... */

  if ( !prune ) {
    push.apply( results, checkSet );
  }

/* ... snip ... */

  if ( !inplace ) {
    result.push.apply( result, ret );
  }

/* ... snip ... */

  slice.call(this);
  push.call(this, ...);

// For internal use only.
// Behaves like an Array's method, not like a jQuery method.
  push: push,

Possibly other uses that I haven't caught. Just a general improvement that could be resued over and over and over.

Change History (3)

comment:1 Changed 10 years ago by ajpiano

This change has already been made for jQuery 1.3.3. Ticket should be marked as closed.

comment:2 Changed 10 years ago by fearphage

The references are made but they are not used. Checking against the nightly:

Array.prototype.slice appears 5 times in the nightly. Array.prototype.push appears 2 times Object.prototype.toString appears 2 times.

comment:3 Changed 9 years ago by dmethvin

Resolution: fixed
Status: newclosed
Note: See TracTickets for help on using tickets.