From f802c84d05f49adcbf8627dedb689225a27afba9 Mon Sep 17 00:00:00 2001 From: Bogdan Mustiata Date: Thu, 5 Mar 2015 12:13:56 +0100 Subject: [PATCH] Use precompiled RegExp. --- Sortable.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/Sortable.js b/Sortable.js index e7bb2fe..c20e3be 100644 --- a/Sortable.js +++ b/Sortable.js @@ -889,6 +889,8 @@ el.removeEventListener(event, fn, false); } + /** @const */ + var RSPACE = /\s+/g; function _toggleClass(el, name, state) { if (el) { @@ -896,11 +898,8 @@ el.classList[state ? 'add' : 'remove'](name); } else { - var className = (' ' + el.className + ' ') - .replace(/\s+/g, ' ') - .replace(' ' + name + ' ', ' ') - .replace(/ /, ' '); - el.className = className + (state ? ' ' + name : ''); + var className = (' ' + el.className + ' ').replace(RSPACE, ' ').replace(' ' + name + ' ', ' '); + el.className = (className + (state ? ' ' + name : '')).replace(RSPACE, ' '); } } }