mirror of
https://github.com/flynx/ImageGrid.git
synced 2025-10-29 02:10:08 +00:00
more optimizations...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
e836eee6e3
commit
534a801f76
@ -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)...
|
||||
|
||||
@ -2948,7 +2948,7 @@ var DataWithTagsPrototype = {
|
||||
// iterate through all the gids (both images and buffer/data)
|
||||
for(var gid in Object.keys(images)
|
||||
.concat(Object.keys(buffer))
|
||||
.unique()){
|
||||
.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
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
@ -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:
|
||||
// {
|
||||
// <item>: <index>,
|
||||
// ...
|
||||
// }
|
||||
//
|
||||
// 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){
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user