diff options
author | Petr Vobornik <pvoborni@redhat.com> | 2015-04-16 18:54:25 +0200 |
---|---|---|
committer | Petr Vobornik <pvoborni@redhat.com> | 2015-05-12 10:53:40 +0200 |
commit | 68f04643d6022707e8ccac9f8b817542d9022119 (patch) | |
tree | 48e0685f88587b68ec9245c6aeccc9c0e290aa82 /install/ui | |
parent | 520bbd001b68bc51a79c2b4a9684fb1c12a582cd (diff) | |
download | freeipa-68f04643d6022707e8ccac9f8b817542d9022119.tar.gz freeipa-68f04643d6022707e8ccac9f8b817542d9022119.tar.xz freeipa-68f04643d6022707e8ccac9f8b817542d9022119.zip |
jQuery.ordered_map: faster creation
Creation of map with e.g. 30K values was very slow. Map checked if a value is
in in the map but it used Array's indexOf method therefore the complexity was
quadratic instead of linear.
Reviewed-By: Martin Babinsky <mbabinsk@redhat.com>
Diffstat (limited to 'install/ui')
-rw-r--r-- | install/ui/src/libs/jquery.ordered-map.js | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/install/ui/src/libs/jquery.ordered-map.js b/install/ui/src/libs/jquery.ordered-map.js index 77d17c56a..19f7b3dd5 100644 --- a/install/ui/src/libs/jquery.ordered-map.js +++ b/install/ui/src/libs/jquery.ordered-map.js @@ -22,6 +22,8 @@ jQuery.ordered_map = jQuery.fn.ordered_map = function(map) { var that = {}; + that._key_indicies = {}; + /** * These variables can be read directly but should not be * modified directly. Use the provided methods instead. @@ -46,12 +48,14 @@ jQuery.ordered_map = jQuery.fn.ordered_map = function(map) { if (typeof position !== 'number') { that.keys.push(key); that.values.push(value); + that._key_indicies[key] = that.keys.length -1; that.length = that.keys.length; } else { if (position < 0) position = 0; else if (position > that.length) position = that.length; that.keys.splice(position, 0, key); that.values.splice(position, 0, value); + that._key_indicies[key] = position; that.length = that.keys.length; } } @@ -112,6 +116,7 @@ jQuery.ordered_map = jQuery.fn.ordered_map = function(map) { var value = that.map[key]; delete that.map[key]; + delete that._key_indicies[key]; that.length = that.keys.length; return value; }; @@ -120,12 +125,13 @@ jQuery.ordered_map = jQuery.fn.ordered_map = function(map) { that.keys = []; that.values = []; that.map = {}; + that._key_indicies = {}; that.length = that.keys.length; return that; }; that.get_key_index = function(key) { - return that.keys.indexOf(key); + return that._key_indicies[key]; }; that.get_key_by_index = function(index) { |