From: fred Date: Sun, 24 Nov 1996 23:14:16 +0000 (+0000) Subject: flower-1.0.8 X-Git-Tag: release/1.5.59~6758 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=6b19a647504a46203b647f446430a7dc3095dbb0;p=lilypond.git flower-1.0.8 --- diff --git a/flower/cursor.cc b/flower/cursor.cc index 2a9f885689..75f607dcaa 100644 --- a/flower/cursor.cc +++ b/flower/cursor.cc @@ -68,27 +68,38 @@ Cursor::operator -( int i ) const return r; } - +/* + warning: can't use Cursor::operator == (Cursor), + since it uses Cursor::operator-(Cursor) + */ template int -Cursor::operator-(Cursor c) const +Cursor::operator-(Cursor rhs) const { - assert(c.list == list); + assert(rhs.list == list); int dif = 0; - Cursor upward(c); - while (upward.ok() && upward.pointer_ != pointer_) { - upward++; + + // search from *this on further up (positive difference) + Cursor c(*this); + while (c.ok() && c.pointer_ != rhs.pointer_) { + c--; dif++; } - if (upward.ok()) - return dif; + if (c.ok()) + goto gotcha; // so, sue me. + + // search in direction of bottom. (negative diff) dif =0; - while (c.ok()&& c.pointer_ != pointer_) { + c=*this; + while (c.ok() && c.pointer_ !=rhs.pointer_) { dif --; - c--; + c++; } assert(c.ok()); + +gotcha: + assert((*this - dif).pointer_ == c.pointer_); return dif; }