]> git.donarmstrong.com Git - lilypond.git/commitdiff
Issue 4397: Arrange Protected_scm variables into single list
authorDavid Kastrup <dak@gnu.org>
Fri, 15 May 2015 20:21:10 +0000 (22:21 +0200)
committerDavid Kastrup <dak@gnu.org>
Thu, 21 May 2015 18:29:34 +0000 (20:29 +0200)
Since we need to allocate one cons cell per protected variable anyway,
we can just arrange them into a single list, making it possible to

a) just require a single scm_permanent_object call, namely for the head

b) have a representation able to return all protected elements, should
we require this at some later point of time

lily/include/protected-scm.hh
lily/protected-scm.cc

index 61d0173dac12ab295f38baf8015ef10bff0de2c5..48a26b15c995a4d948a5c4974dd9da02f414cb71 100644 (file)
@@ -43,6 +43,8 @@
 class Protected_scm
 {
   SCM object_;
+  static SCM list_;
+  static SCM last_;
   Protected_scm (Protected_scm const &);
 public:
   Protected_scm ();
index c0eb374bafc70c8e762774a5ada363735f46a505..225c64dc60fc220bf03910f25575a539a3ecbdfd 100644 (file)
@@ -46,13 +46,25 @@ Protected_scm::~Protected_scm ()
   object_ = SCM_UNDEFINED;
 }
 
+SCM Protected_scm::list_ = SCM_EOL;
+SCM Protected_scm::last_ = SCM_EOL;
+
 Protected_scm &
 Protected_scm::operator = (SCM s)
 {
   if (SCM_CONSP (object_))
     SCM_SETCAR (object_, s);
+  else if (SCM_IMP (s))
+    object_ = s;
   else
-    object_ = SCM_NIMP (s) ? scm_permanent_object (scm_list_1 (s)) : s;
+    {
+      s = scm_list_1 (s);
+      if (SCM_CONSP (last_))
+        SCM_SETCDR (last_, s);
+      else
+        list_ = scm_permanent_object (s);
+      last_ = object_ = s;
+    }
 
   return *this;
 }