Skip to content

Commit 26a6338

Browse files
committed
Change splice.call(arguments, ..) to use slice
- Bypasses issue of usage incorrectly omitting 2nd argument to `splice` - More clear of intent; `slice` does not modifify `arguments` - `slice` is faster across all desktop browsers, by varying degrees - Probably due to parameter-aliasing and de-opts when modified. - Both `slice` and `splice` create a new Array object
1 parent bae732c commit 26a6338

6 files changed

Lines changed: 8 additions & 8 deletions

File tree

src/core/PluginManager.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ Phaser.PluginManager.prototype = {
5252
*/
5353
add: function (plugin) {
5454

55-
var args = Array.prototype.splice.call(arguments, 1);
55+
var args = Array.prototype.slice.call(arguments, 1);
5656
var result = false;
5757

5858
// Prototype?

src/core/StateManager.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ Phaser.StateManager.prototype = {
308308

309309
if (arguments.length > 2)
310310
{
311-
this._args = Array.prototype.splice.call(arguments, 2);
311+
this._args = Array.prototype.slice.call(arguments, 2);
312312
}
313313

314314
},

src/gameobjects/GameObjectCreator.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ Phaser.GameObjectCreator.prototype = {
414414
*/
415415
filter: function (filter) {
416416

417-
var args = Array.prototype.splice.call(arguments, 1);
417+
var args = Array.prototype.slice.call(arguments, 1);
418418

419419
var filter = new Phaser.Filter[filter](this.game);
420420

src/gameobjects/GameObjectFactory.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ Phaser.GameObjectFactory.prototype = {
531531
*/
532532
filter: function (filter) {
533533

534-
var args = Array.prototype.splice.call(arguments, 1);
534+
var args = Array.prototype.slice.call(arguments, 1);
535535

536536
var filter = new Phaser.Filter[filter](this.game);
537537

src/time/Timer.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ Phaser.Timer.prototype = {
242242
*/
243243
add: function (delay, callback, callbackContext) {
244244

245-
return this.create(delay, false, 0, callback, callbackContext, Array.prototype.splice.call(arguments, 3));
245+
return this.create(delay, false, 0, callback, callbackContext, Array.prototype.slice.call(arguments, 3));
246246

247247
},
248248

@@ -264,7 +264,7 @@ Phaser.Timer.prototype = {
264264
*/
265265
repeat: function (delay, repeatCount, callback, callbackContext) {
266266

267-
return this.create(delay, false, repeatCount, callback, callbackContext, Array.prototype.splice.call(arguments, 4));
267+
return this.create(delay, false, repeatCount, callback, callbackContext, Array.prototype.slice.call(arguments, 4));
268268

269269
},
270270

@@ -285,7 +285,7 @@ Phaser.Timer.prototype = {
285285
*/
286286
loop: function (delay, callback, callbackContext) {
287287

288-
return this.create(delay, true, 0, callback, callbackContext, Array.prototype.splice.call(arguments, 3));
288+
return this.create(delay, true, 0, callback, callbackContext, Array.prototype.slice.call(arguments, 3));
289289

290290
},
291291

src/utils/ArraySet.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ Phaser.ArraySet.prototype = {
168168
*/
169169
callAll: function (key) {
170170

171-
var args = Array.prototype.splice.call(arguments, 1);
171+
var args = Array.prototype.slice.call(arguments, 1);
172172

173173
var i = this.list.length;
174174

0 commit comments

Comments
 (0)