Nasal: use new positioned.diff
This commit is contained in:
parent
ff071bd858
commit
5e2801461c
1 changed files with 6 additions and 25 deletions
|
@ -344,32 +344,14 @@ var PositionedSearch = {
|
|||
if (a == nil or b == nil) return 0;
|
||||
return (a == b or a.id == b.id);
|
||||
},
|
||||
condense: func(vec) {
|
||||
var ret = [];
|
||||
foreach (var e; vec)
|
||||
if (e != nil) append(ret, e);
|
||||
return ret;
|
||||
},
|
||||
diff: func(old, new) {
|
||||
var removed = old~[]; #copyvec
|
||||
var added = new~[];
|
||||
# Mark common elements from removed and added:
|
||||
forindex (OUTER; var i; removed)
|
||||
forindex (var j; new)
|
||||
if (me._equals(removed[i], added[j])) {
|
||||
removed[i] = added[j] = nil;
|
||||
continue OUTER;
|
||||
}
|
||||
# And remove those common elements, returning the result:
|
||||
return [new, me.condense(removed), me.condense(added)];
|
||||
},
|
||||
update: func(searchCmd=nil) {
|
||||
if (searchCmd == nil) searchCmd = me.searchCmd;
|
||||
(me.result, var removed, var added) = me.diff(me.result, call(searchCmd, nil, me.obj));
|
||||
foreach (var e; removed)
|
||||
call(me.onRemoved, [e], me.obj);
|
||||
foreach (var e; added)
|
||||
call(me.onAdded, [e], me.obj);
|
||||
var old = me.result~[]; #copyvec
|
||||
me.result = call(searchCmd, nil, me.obj);
|
||||
positioned.diff( old,
|
||||
me.result,
|
||||
func call(me.onAdded, arg, me.obj),
|
||||
func call(me.onRemoved, arg, me.obj) );
|
||||
},
|
||||
# this is the worst case scenario: switching from 640 to 320 (or vice versa)
|
||||
test: func(from=640, to=320) {
|
||||
|
@ -384,4 +366,3 @@ var PositionedSearch = {
|
|||
}); # ~ takes
|
||||
}, # of test
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue