]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/dimension-cache.cc
release: 1.3.28
[lilypond.git] / lily / dimension-cache.cc
index aacf58aadc0cc5ed7b115a1ba268968e814c89e8..69ff282b0a929ec1f3bb13a89795bc16e600e8c8 100644 (file)
@@ -3,7 +3,7 @@
   
   source file of the GNU LilyPond music typesetter
   
-  (c) 1998--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+  (c) 1998--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
  */
 
 #include "dimension-cache.hh"
@@ -31,7 +31,6 @@ void
 Dimension_cache::init()
 {
   callback_l_ =0;
-
   basic_offset_ =0.0;
   extra_offset_ =0.0;
   
@@ -43,27 +42,6 @@ Dimension_cache::init()
 }
 
 
-void
-Dimension_cache::invalidate ()
-{
-  off_valid_b_ =false;
-  valid_b_ = false;
-}
-
-
-void
-Dimension_cache::set_offset (Real x)
-{
-  // ugh!
-  /*
-
-    UGH ! UGH !
-    
-   */
-  
-  extra_offset_ = x;
-}
-
 void
 Dimension_cache::translate (Real x)
 {
@@ -99,32 +77,29 @@ Dimension_cache::axis () const
 Real
 Dimension_cache::get_offset () const
 {
-  if (!off_valid_b_)
+  Dimension_cache *me = (Dimension_cache*) this;
+  while (off_callbacks_.size ())
     {
-      Dimension_cache *d = (Dimension_cache*) this;
-
-      d->basic_offset_ =0.0;
-      d->off_valid_b_ = true;
-      for (int i=0; i < off_callbacks_.size (); i++)
-       d->basic_offset_ += (*off_callbacks_[i]) (d);
+      Offset_cache_callback c = me->off_callbacks_[0];
+      me->off_callbacks_.del (0);
+      me->basic_offset_ += (*c) (me);
     }
-
   return basic_offset_ + extra_offset_;
 }
 
 Dimension_cache *
 Dimension_cache::common_refpoint (Dimension_cache const* s) const
 {
-  Link_array<Dimension_cache> my_groups;
-  for (Dimension_cache const *c = this; c ; c = c->parent_l_)
-    my_groups.push ((Dimension_cache*)c);
-  
-  Dimension_cache const *common=0;
-  
-  for (Dimension_cache const * d = s; !common && d; d = d->parent_l_)
-    common = (Dimension_cache const*)my_groups.find_l (d);
-
-  return (Dimension_cache*) common;
+  /*
+    I don't like the quadratic aspect of this code. Maybe this should
+    be rewritten some time, but the largest chain of parents might be
+    10 high or so, so it shouldn't be a real issue. */
+  for (Dimension_cache const *c = this; c; c = c->parent_l_)
+    for (Dimension_cache const * d = s; d; d = d->parent_l_)
+      if (d == c)
+       return (Dimension_cache*)d;
+
+  return 0;
 }
 
 Interval
@@ -144,7 +119,6 @@ Dimension_cache::get_dim () const
     }
   else if (!valid_b_)
     {
-
       nc->dim_= (*callback_l_ ) (nc);
       nc->valid_b_ = true;
     }