From 28d702692ec7fa5f4de6a60a7e165ec3305a5daf Mon Sep 17 00:00:00 2001 From: David Kastrup Date: Fri, 15 May 2015 22:21:10 +0200 Subject: [PATCH] Issue 4397: Arrange Protected_scm variables into single list 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 | 2 ++ lily/protected-scm.cc | 14 +++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lily/include/protected-scm.hh b/lily/include/protected-scm.hh index 61d0173dac..48a26b15c9 100644 --- a/lily/include/protected-scm.hh +++ b/lily/include/protected-scm.hh @@ -43,6 +43,8 @@ class Protected_scm { SCM object_; + static SCM list_; + static SCM last_; Protected_scm (Protected_scm const &); public: Protected_scm (); diff --git a/lily/protected-scm.cc b/lily/protected-scm.cc index c0eb374baf..225c64dc60 100644 --- a/lily/protected-scm.cc +++ b/lily/protected-scm.cc @@ -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; } -- 2.39.2