From 4ab63e70fee9c087cd8eff7fcb6e9720ebbaa55e Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Fri, 22 Dec 2017 09:37:26 -0500 Subject: [PATCH] code review: avoid Array.splice/unshift The array size stays the same, items are just moved around. --- src/js/utils.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/js/utils.js b/src/js/utils.js index 970b72fe9..709937524 100644 --- a/src/js/utils.js +++ b/src/js/utils.js @@ -373,8 +373,11 @@ lookup: function(key) { var value = this.map.get(key); if ( value !== undefined && this.array[0] !== key ) { - this.array.splice(this.array.indexOf(key), 1); - this.array.unshift(key); + var i = this.array.indexOf(key); + do { + this.array[i] = this.array[i-1]; + } while ( --i ); + this.array[0] = key; } return value; },