From 720bdb8c4f0c75f17410b6f182343948d89aef61 Mon Sep 17 00:00:00 2001 From: Jean Boussier Date: Wed, 12 Sep 2012 14:47:23 -0400 Subject: [PATCH] Store last mouse position in a variable instead of document datastore It's hundred times faster. See http://jsperf.com/data-vs-variable --- select2.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/select2.js b/select2.js index 521629dc..35385cad 100644 --- a/select2.js +++ b/select2.js @@ -40,7 +40,7 @@ return; } - var KEY, AbstractSelect2, SingleSelect2, MultiSelect2, nextUid, sizer; + var KEY, AbstractSelect2, SingleSelect2, MultiSelect2, nextUid, sizer, lastMousePosition; KEY = { TAB: 9, @@ -163,7 +163,7 @@ } $(document).delegate("body", "mousemove", function (e) { - $.data(document, "select2-lastpos", {x: e.pageX, y: e.pageY}); + lastMousePosition = {x: e.pageX, y: e.pageY}; }); /** @@ -174,7 +174,7 @@ */ function installFilteredMouseMove(element) { element.bind("mousemove", function (e) { - var lastpos = $.data(document, "select2-lastpos"); + var lastpos = lastMousePosition; if (lastpos === undefined || lastpos.x !== e.pageX || lastpos.y !== e.pageY) { $(e.target).trigger("mousemove-filtered", e); }