some tweaks, cleanup + removed caching form marks...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2014-01-17 04:49:02 +04:00
parent 9b3d1a9221
commit 2d7f11fa75

View File

@ -27,10 +27,6 @@ var MARKED_FILE_DEFAULT = 'marked.json'
var MARKED_FILE_PATTERN = /^[0-9]*-marked.json$/ var MARKED_FILE_PATTERN = /^[0-9]*-marked.json$/
// NOTE: if this is set to null, caching will be disabled...
var _UNMARKED_CACHE = {}
/********************************************************************** /**********************************************************************
* helpers... * helpers...
@ -79,15 +75,6 @@ function _removeMark(cls, gid, image){
} }
// Invalidate unmarked image cache...
//
function invalidateMarksCache(){
if(_UNMARKED_CACHE != null){
_UNMARKED_CACHE = {}
}
}
function makeMarkedLister(get_marked){ function makeMarkedLister(get_marked){
return function(mode){ return function(mode){
var marked = get_marked() var marked = get_marked()
@ -102,20 +89,17 @@ function makeMarkedLister(get_marked){
// Make lister of unmarked images... // Make lister of unmarked images...
// //
// mode can be: // The resulting function can take one argument (mode) which can be:
// - 'ribbon' // - null - default, same as 'all'
// - 'all' // - 'all' - process all loaded gids
// - number - ribbon index // - 'ribbon' - process curent ribbon
// - list - list of gids used as source // - number - ribbon index to process
// - null - same as all // - Array - list of gids to filter
// function makeUnmarkedLister(get_marked){
// XXX with sparce lists this is trivial: get all the null indexes...
function makeUnmarkedLister(get_marked, get_cache){
return function(mode){ return function(mode){
mode = mode == null ? 'all' : mode mode = mode == null ? 'all' : mode
var marked = get_marked() var marked = get_marked()
var cache = get_cache != null ? get_cache() : null
var gids = mode == 'all' ? getLoadedGIDs() var gids = mode == 'all' ? getLoadedGIDs()
: mode.constructor.name == 'Array' ? getLoadedGIDs(mode) : mode.constructor.name == 'Array' ? getLoadedGIDs(mode)
@ -131,20 +115,17 @@ function makeUnmarkedLister(get_marked, get_cache){
return res return res
} }
} }
// The same as makeUnmarkedLister(..) but designed for sparse lists...
//
// NOTE: this is about an order of magnitude faster than the non-sparse // NOTE: this is about an order of magnitude faster than the non-sparse
// version... // version...
function makeUnmarkedSparseLister(get_marked, get_cache){ function makeUnmarkedSparseLister(get_marked){
// mode can be:
// - null - default, same as 'all'
// - 'all' - process all loases gids
// - 'ribbon' - process curent ribbon
// - number - ribbon index
// - Array - list of gids
return function(mode){ return function(mode){
mode = mode == null ? 'all' : mode mode = mode == null ? 'all' : mode
var marked = get_marked() var marked = get_marked()
//var cache = get_cache != null ? get_cache() : null
var res = mode == 'all' ? var res = mode == 'all' ?
DATA.order.slice() DATA.order.slice()
@ -173,9 +154,7 @@ function makeUnmarkedSparseLister(get_marked, get_cache){
var getMarked = makeMarkedLister(function(){ return MARKED }) var getMarked = makeMarkedLister(function(){ return MARKED })
var getUnmarked = makeUnmarkedSparseLister( var getUnmarked = makeUnmarkedSparseLister(function(){ return MARKED })
function(){ return MARKED },
function(){ return _UNMARKED_CACHE })
// XXX make this undefined tolerant -- sparse list compatibility... // XXX make this undefined tolerant -- sparse list compatibility...
@ -762,7 +741,6 @@ var saveFileMarks = makeFileSaver(
function marksUpdated(){ function marksUpdated(){
fileUpdated('Marks') fileUpdated('Marks')
invalidateMarksCache()
$('.viewer').trigger('marksUpdated') $('.viewer').trigger('marksUpdated')
} }
@ -809,9 +787,6 @@ function setupMarks(viewer){
marksUpdated() marksUpdated()
} }
}) })
.on('baseURLChanged', function(){
invalidateMarksCache()
})
} }
SETUP_BINDINGS.push(setupMarks) SETUP_BINDINGS.push(setupMarks)