diff --git a/ui (gen4)/features/core.js b/ui (gen4)/features/core.js index 759a6487..264389ff 100755 --- a/ui (gen4)/features/core.js +++ b/ui (gen4)/features/core.js @@ -1513,7 +1513,9 @@ var ChangesActions = actions.Actions({ if(changes[section] === true){ return } - changes[section] = (changes[section] || []).concat(items).unique() + changes[section] = (changes[section] || []) + .concat(items) + .uniqueStrings() this.changes = changes // section(s)... diff --git a/ui (gen4)/imagegrid/data.js b/ui (gen4)/imagegrid/data.js index 046a3f1b..bf2b304f 100755 --- a/ui (gen4)/imagegrid/data.js +++ b/ui (gen4)/imagegrid/data.js @@ -2947,8 +2947,8 @@ var DataWithTagsPrototype = { if(mode == 'reset'){ // iterate through all the gids (both images and buffer/data) for(var gid in Object.keys(images) - .concat(Object.keys(buffer)) - .unique()){ + .concat(Object.keys(buffer)) + .uniqueStrings()){ // no tags / remove... if(buffer[gid] == null || buffer[gid].tags.length == 0){ // the image exists and has tags... @@ -2976,7 +2976,9 @@ var DataWithTagsPrototype = { for(var gid in buffer){ var img = _get(images, gid) var l = img.tags.length - img.tags = img.tags.concat(buffer[gid].tags).unique() + img.tags = img.tags + .concat(buffer[gid].tags) + .uniqueStrings() // we are updated iff length changed... // NOTE: this is true as we are not removing anything // thus the length can only increase if changes are diff --git a/ui (gen4)/imagegrid/ribbons.js b/ui (gen4)/imagegrid/ribbons.js index cdfba758..259d432a 100755 --- a/ui (gen4)/imagegrid/ribbons.js +++ b/ui (gen4)/imagegrid/ribbons.js @@ -1633,12 +1633,29 @@ var RibbonsPrototype = { })) }, // XXX add options for images to preload and only then do the update... + // XXX really slow for very large numbers of input images/gids... updateImage: function(image, gid, size, sync, callback){ var that = this - image = (image == '*' ? this.viewer.find(IMAGE) - : image == null - || typeof(image) == typeof('str') ? this.getImage(image) - : $(image)) + var imgs = this.viewer.find(IMAGE) + + // reduce the length of input image set... + // NOTE: this will make things substantially faster for very large + // input sets... + if(image instanceof Array && image.length > imgs.length){ + image = imgs + .filter(function(_, img){ + return image.indexOf(img) >= 0 + || image.indexOf(that.elemGID(img)) >= 0 }) + .map(function(_, img){ + return that.elemGID(img) }) + .toArray() + } + // normalize... + image = image == '*' ? + imgs + : (image == null || typeof(image) == typeof('str')) ? + this.getImage(image) + : $(image) sync = sync == null ? this.load_img_sync : sync size = size == null ? this.getVisibleImageSize('max') : size diff --git a/ui (gen4)/lib/util.js b/ui (gen4)/lib/util.js index f4cb37d0..4ee0d991 100755 --- a/ui (gen4)/lib/util.js +++ b/ui (gen4)/lib/util.js @@ -40,9 +40,23 @@ Object.defineProperty(Object.prototype, 'run', { Array.prototype.compact = function(){ return this.filter(function(){ return true }) } -Array.prototype.toKeys = function(){ + + +// Convert an array to object... +// +// Format: +// { +// : , +// ... +// } +// +// NOTE: items should be strings, other types will get converted to +// strings and thus may mess things up. +// NOTE: this will forget repeating items... +// NOTE: normalize will slow things down... +Array.prototype.toKeys = function(normalize){ return this.reduce(function(r, e, i){ - r[e] = i + r[normalize ? normalize(e) : e] = i return r }, {}) } @@ -57,7 +71,7 @@ Array.prototype.compact = function(){ */ -// return an array with duplicate elements removed... +// Return an array with duplicate elements removed... // // NOTE: we are not using an Object as an index here as an Array can // contain any type of item while Object keys can only be strings... @@ -72,6 +86,12 @@ Array.prototype.unique = function(normalize){ } +// Special case of .unique, allot faster on arrays of strings... +// +Array.prototype.uniqueStrings = function(normalize){ + return Object.keys(this.toKeys(normalize)) } + + // Compare two arrays... // Array.prototype.cmp = function(other){