]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/nested-property.cc
Imported Upstream version 2.16.0
[lilypond.git] / lily / nested-property.cc
index db897d3fd847d60cce195e926889eced04c9ec23..9c3cc73387a74dbd2533206b8148a03308871225 100644 (file)
@@ -1,7 +1,6 @@
 #include "context.hh"
 #include "grob.hh"
 
-
 /*
   Drop symbol from the list alist..alist_end.
  */
@@ -14,10 +13,10 @@ evict_from_alist (SCM symbol, SCM alist, SCM alist_end)
   while (alist != alist_end)
     {
       if (ly_is_equal (scm_caar (alist), symbol))
-       {
-         alist = scm_cdr (alist);
-         break;
-       }
+        {
+          alist = scm_cdr (alist);
+          break;
+        }
 
       *tail = scm_cons (scm_car (alist), SCM_EOL);
       tail = SCM_CDRLOC (*tail);
@@ -61,9 +60,7 @@ nested_property_alist (SCM alist, SCM prop_path, SCM value)
 SCM
 nested_property_revert_alist (SCM alist, SCM prop_path)
 {
-  int copy_count = 0;
-  bool drop = false;
-  assert(scm_is_pair (prop_path));
+  assert (scm_is_pair (prop_path));
 
   SCM wanted_sym = scm_car (prop_path);
 
@@ -73,62 +70,37 @@ nested_property_revert_alist (SCM alist, SCM prop_path)
     {
       SCM sub_sym = scm_caar (s);
       SCM old_val = scm_cdar (s);
-      drop = false;
 
       if (sub_sym == wanted_sym)
-       {
-         if (scm_is_pair (scm_cdr (prop_path)))
-           {
-             SCM new_val = nested_property_revert_alist (old_val, scm_cdr (prop_path));
-
-             /* nothing changed: drop newly constructed list. */
-             if (old_val == new_val)
-               return alist;
-
-             *tail = scm_acons (sub_sym, new_val, SCM_EOL);
-             tail = SCM_CDRLOC(*tail);
-              *tail = scm_cdr (s);
-              return new_list;
-           }
-         else
-           {
-              /* old value should be dropped only if we have another copy of it in the alist */
-              copy_count++;
-              /*
-                Only drop the first instance found.
-                the overridden value is always the first
-                if this was the only copy, we will return
-                the original list anyways so it is not relevant
-                if we drop this pair
-              */
-              if (copy_count == 1)
-                drop = true;
-           }
-         /* we now iterate over every item */
-       }
-      /*
-        Make a new list with every item
-        except for the eventual dropped one
-      */
-      if (!drop)
         {
-          *tail = scm_acons (sub_sym, old_val, SCM_EOL);
-          tail = SCM_CDRLOC (*tail);
+          if (scm_is_pair (scm_cdr (prop_path)))
+            {
+              SCM new_val = nested_property_revert_alist (old_val, scm_cdr (prop_path));
+
+              /* nothing changed: drop newly constructed list. */
+              if (old_val == new_val)
+                return alist;
+
+              *tail = scm_acons (sub_sym, new_val, SCM_EOL);
+              tail = SCM_CDRLOC (*tail);
+            }
+          else
+            {
+              /* old value is dropped. */
+            }
+
+          *tail = scm_cdr (s);
+          return new_list;
         }
+
+      *tail = scm_acons (sub_sym, old_val, SCM_EOL);
+      tail = SCM_CDRLOC (*tail);
     }
 
-  /*
-    If we find more than one copy of the property
-    push the new list, else it means we are trying to
-    revert the original value
-  */
-  if (copy_count > 1)
-    return new_list;
-  else
-    return alist;
+  /* Wanted symbol not found: drop newly constructed list. */
+  return alist;
 }
 
-
 void
 set_nested_property (Grob *me, SCM big_to_small, SCM value)
 {
@@ -138,4 +110,3 @@ set_nested_property (Grob *me, SCM big_to_small, SCM value)
 
   me->set_property (scm_car (big_to_small), alist);
 }
-