mirror of
				https://github.com/flynx/ImageGrid.git
				synced 2025-10-31 03:10:07 +00:00 
			
		
		
		
	rewritten data.getImages(..) removing a .compact() related bottleneck...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
		
							parent
							
								
									7a4ed670ee
								
							
						
					
					
						commit
						ce5e7350ab
					
				| @ -849,7 +849,8 @@ var DataPrototype = { | |||||||
| 	// 		one of the contained images (first?)
 | 	// 		one of the contained images (first?)
 | ||||||
| 	// XXX for some reason negative target number (ribbon number) 
 | 	// XXX for some reason negative target number (ribbon number) 
 | ||||||
| 	// 		breaks this...
 | 	// 		breaks this...
 | ||||||
| 	getImages: function(target, count, mode){ | 	/* | ||||||
|  | 	_getImages: function(target, count, mode){ | ||||||
| 		target = (target == null && count == null) ? 'loaded' : target | 		target = (target == null && count == null) ? 'loaded' : target | ||||||
| 		mode = mode == null ? 'around' : mode | 		mode = mode == null ? 'around' : mode | ||||||
| 		var list | 		var list | ||||||
| @ -898,6 +899,7 @@ var DataPrototype = { | |||||||
| 		// get the ribbon gids...
 | 		// get the ribbon gids...
 | ||||||
| 		if(list == null){ | 		if(list == null){ | ||||||
| 			list = this.ribbons[this.getRibbon(target)]  | 			list = this.ribbons[this.getRibbon(target)]  | ||||||
|  | 			// XXX compacting here is bad, we'll be handling the whole ribbon...
 | ||||||
| 			list = list != null ? list.compact() : [] | 			list = list != null ? list.compact() : [] | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| @ -914,15 +916,24 @@ var DataPrototype = { | |||||||
| 			var from = i - Math.floor(count) | 			var from = i - Math.floor(count) | ||||||
| 			var to = i + Math.ceil(count) | 			var to = i + Math.ceil(count) | ||||||
| 
 | 
 | ||||||
|  | 			var pre = Math.floor(count) | ||||||
|  | 			var post = Math.ceil(count) | ||||||
|  | 
 | ||||||
| 		} else if(mode == 'before'){ | 		} else if(mode == 'before'){ | ||||||
| 			// NOTE: we are shifting by 1 to include the target...
 | 			// NOTE: we are shifting by 1 to include the target...
 | ||||||
| 			var from = (i - count) + 1 | 			var from = (i - count) + 1 | ||||||
| 			var to = i + 1 | 			var to = i + 1 | ||||||
| 
 | 
 | ||||||
|  | 			var pre = count - 1  | ||||||
|  | 			var post = 0  | ||||||
|  | 
 | ||||||
| 		} else if(mode == 'after'){ | 		} else if(mode == 'after'){ | ||||||
| 			var from = i | 			var from = i | ||||||
| 			var to = i + count | 			var to = i + count | ||||||
| 
 | 
 | ||||||
|  | 			var pre = 0 | ||||||
|  | 			var post = count - 1 | ||||||
|  | 
 | ||||||
| 		} else { | 		} else { | ||||||
| 			// XXX bad mode....
 | 			// XXX bad mode....
 | ||||||
| 			return null | 			return null | ||||||
| @ -932,6 +943,127 @@ var DataPrototype = { | |||||||
| 		from = Math.max(0, from) | 		from = Math.max(0, from) | ||||||
| 
 | 
 | ||||||
| 		return list.slice(from, to) | 		return list.slice(from, to) | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 		var res = [target] | ||||||
|  | 
 | ||||||
|  | 		// pre...
 | ||||||
|  | 		for(var n = i-1; n >= 0 && pre > 0; n--){ | ||||||
|  | 			if(n in list){ | ||||||
|  | 				res.push(list[n]) | ||||||
|  | 				pre-- | ||||||
|  | 			} | ||||||
|  | 		} | ||||||
|  | 
 | ||||||
|  | 		res.reverse() | ||||||
|  | 		// post...
 | ||||||
|  | 		for(var n = i+1; n < list.length && post > 0; n--){ | ||||||
|  | 			if(n in list){ | ||||||
|  | 				res.push(list[n]) | ||||||
|  | 				post-- | ||||||
|  | 			} | ||||||
|  | 		} | ||||||
|  | 		return res | ||||||
|  | 	}, | ||||||
|  | 	*/ | ||||||
|  | 	// NOTE: this is a partial rewrite avoiding .compact() as much as 
 | ||||||
|  | 	// 		possible and restricting it to as small a subset as possible
 | ||||||
|  | 	getImages: function(target, count, mode){ | ||||||
|  | 		target = (target == null && count == null) ? 'loaded' : target | ||||||
|  | 		mode = mode == null ? 'around' : mode | ||||||
|  | 		var list | ||||||
|  | 
 | ||||||
|  | 		// normalize target and build the source list...
 | ||||||
|  | 
 | ||||||
|  | 		// 'current' ribbon...
 | ||||||
|  | 		target = target == 'current' ? this.current : target | ||||||
|  | 
 | ||||||
|  | 		// get all gids...
 | ||||||
|  | 		if(target == 'all'){ | ||||||
|  | 			list = this.order | ||||||
|  | 			target = null | ||||||
|  | 
 | ||||||
|  | 		// get loaded only gids...
 | ||||||
|  | 		} else if(target == 'loaded'){ | ||||||
|  | 			var res = [] | ||||||
|  | 			var ribbons = this.ribbons | ||||||
|  | 			for(var k in ribbons){ | ||||||
|  | 				this.makeSparseImages(ribbons[k], res) | ||||||
|  | 			} | ||||||
|  | 			list = res.compact() | ||||||
|  | 			target = null  | ||||||
|  | 
 | ||||||
|  | 		// filter out the unloaded gids from given list...
 | ||||||
|  | 		} else if(target != null && target.constructor === Array){ | ||||||
|  | 			var loaded = count == 'current' ? this.getImages('current') | ||||||
|  | 				: count in this.ribbons ? this.ribbons[count].compact() | ||||||
|  | 				: typeof(count) == typeof(123) ?  | ||||||
|  | 					this.ribbons[this.getRibbon(count)].compact() | ||||||
|  | 				: this.getImages('loaded') | ||||||
|  | 			count = null  | ||||||
|  | 
 | ||||||
|  | 			list = target.filter(function(e){ | ||||||
|  | 				return loaded.indexOf(e) >= 0 | ||||||
|  | 			}) | ||||||
|  | 
 | ||||||
|  | 			target = null  | ||||||
|  | 
 | ||||||
|  | 		// target is ribbon gid...
 | ||||||
|  | 		} else if(target in this.ribbons){ | ||||||
|  | 			list = this.ribbons[target] | ||||||
|  | 		} | ||||||
|  | 
 | ||||||
|  | 		// NOTE: list can be null if we got an image gid or ribbon order...
 | ||||||
|  | 		// get the ribbon gids...
 | ||||||
|  | 		list = list || this.ribbons[this.getRibbon(target)] || [] | ||||||
|  | 
 | ||||||
|  | 		if(count == null){ | ||||||
|  | 			return list.compact() | ||||||
|  | 		} | ||||||
|  | 
 | ||||||
|  | 		target = this.getImage(target) | ||||||
|  | 		var i = list.indexOf(target) | ||||||
|  | 
 | ||||||
|  | 		// prepare to slice the list...
 | ||||||
|  | 		if(mode == 'around'){ | ||||||
|  | 			count = count/2 | ||||||
|  | 			var pre = Math.floor(count) | ||||||
|  | 			var post = Math.ceil(count) - 1 | ||||||
|  | 
 | ||||||
|  | 		} else if(mode == 'before'){ | ||||||
|  | 			var pre = count - 1  | ||||||
|  | 			var post = 0  | ||||||
|  | 
 | ||||||
|  | 		} else if(mode == 'after'){ | ||||||
|  | 			var pre = 0 | ||||||
|  | 			var post = count - 1 | ||||||
|  | 
 | ||||||
|  | 		} else { | ||||||
|  | 			// XXX bad mode....
 | ||||||
|  | 			return null | ||||||
|  | 		} | ||||||
|  | 
 | ||||||
|  | 		var res = [target] | ||||||
|  | 
 | ||||||
|  | 		// pre...
 | ||||||
|  | 		for(var n = i-1; n >= 0 && pre > 0; n--){ | ||||||
|  | 			if(n in list){ | ||||||
|  | 				res.push(list[n]) | ||||||
|  | 				pre-- | ||||||
|  | 			} | ||||||
|  | 		} | ||||||
|  | 
 | ||||||
|  | 		res.reverse() | ||||||
|  | 
 | ||||||
|  | 		// post...
 | ||||||
|  | 		for(var n = i+1; n < list.length && post > 0; n++){ | ||||||
|  | 			if(n in list){ | ||||||
|  | 				res.push(list[n]) | ||||||
|  | 				post-- | ||||||
|  | 			} | ||||||
|  | 		} | ||||||
|  | 
 | ||||||
|  | 		return res | ||||||
| 	}, | 	}, | ||||||
| 
 | 
 | ||||||
| 	// Get ribbon...
 | 	// Get ribbon...
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user