From 5e2801461ce0ae82e809fb3af613b4dafca9c5ee Mon Sep 17 00:00:00 2001 From: Thomas Geymayer Date: Sun, 8 Dec 2013 20:27:37 +0100 Subject: [PATCH] Nasal: use new positioned.diff --- Nasal/geo.nas | 31 ++++++------------------------- 1 file changed, 6 insertions(+), 25 deletions(-) diff --git a/Nasal/geo.nas b/Nasal/geo.nas index 7408b1e0f..552307d76 100644 --- a/Nasal/geo.nas +++ b/Nasal/geo.nas @@ -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 }; -