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){
|
if(changes[section] === true){
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
changes[section] = (changes[section] || []).concat(items).unique()
|
changes[section] = (changes[section] || [])
|
||||||
|
.concat(items)
|
||||||
|
.uniqueStrings()
|
||||||
this.changes = changes
|
this.changes = changes
|
||||||
|
|
||||||
// section(s)...
|
// section(s)...
|
||||||
|
|||||||
@ -2947,8 +2947,8 @@ var DataWithTagsPrototype = {
|
|||||||
if(mode == 'reset'){
|
if(mode == 'reset'){
|
||||||
// iterate through all the gids (both images and buffer/data)
|
// iterate through all the gids (both images and buffer/data)
|
||||||
for(var gid in Object.keys(images)
|
for(var gid in Object.keys(images)
|
||||||
.concat(Object.keys(buffer))
|
.concat(Object.keys(buffer))
|
||||||
.unique()){
|
.uniqueStrings()){
|
||||||
// no tags / remove...
|
// no tags / remove...
|
||||||
if(buffer[gid] == null || buffer[gid].tags.length == 0){
|
if(buffer[gid] == null || buffer[gid].tags.length == 0){
|
||||||
// the image exists and has tags...
|
// the image exists and has tags...
|
||||||
@ -2976,7 +2976,9 @@ var DataWithTagsPrototype = {
|
|||||||
for(var gid in buffer){
|
for(var gid in buffer){
|
||||||
var img = _get(images, gid)
|
var img = _get(images, gid)
|
||||||
var l = img.tags.length
|
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...
|
// we are updated iff length changed...
|
||||||
// NOTE: this is true as we are not removing anything
|
// NOTE: this is true as we are not removing anything
|
||||||
// thus the length can only increase if changes are
|
// 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 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){
|
updateImage: function(image, gid, size, sync, callback){
|
||||||
var that = this
|
var that = this
|
||||||
image = (image == '*' ? this.viewer.find(IMAGE)
|
var imgs = this.viewer.find(IMAGE)
|
||||||
: image == null
|
|
||||||
|| typeof(image) == typeof('str') ? this.getImage(image)
|
// reduce the length of input image set...
|
||||||
: $(image))
|
// 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
|
sync = sync == null ? this.load_img_sync : sync
|
||||||
size = size == null ? this.getVisibleImageSize('max') : size
|
size = size == null ? this.getVisibleImageSize('max') : size
|
||||||
|
|
||||||
|
|||||||
@ -40,9 +40,23 @@ Object.defineProperty(Object.prototype, 'run', {
|
|||||||
Array.prototype.compact = function(){
|
Array.prototype.compact = function(){
|
||||||
return this.filter(function(){ return true })
|
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){
|
return this.reduce(function(r, e, i){
|
||||||
r[e] = i
|
r[normalize ? normalize(e) : e] = i
|
||||||
return r
|
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
|
// 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...
|
// 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...
|
// Compare two arrays...
|
||||||
//
|
//
|
||||||
Array.prototype.cmp = function(other){
|
Array.prototype.cmp = function(other){
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user