lilypond-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Gives each grob an integer hash. (issue4515166)


From: mtsolo
Subject: Gives each grob an integer hash. (issue4515166)
Date: Tue, 31 May 2011 15:57:51 +0000

Reviewers: ,

Message:
This patch'll be useful for some advanced tweaks I'm doing while running
LilyPond in multiple passes.  Lemme know if it looks all right.

Cheers,
MS

Description:
Gives each grob an integer hash.

Please review this at http://codereview.appspot.com/4515166/

Affected files:
  M lily/grob-scheme.cc
  M lily/grob.cc
  M lily/include/grob.hh


Index: lily/grob-scheme.cc
diff --git a/lily/grob-scheme.cc b/lily/grob-scheme.cc
index 9554883464f4d5c5d74d47cac737a286e42e41c4..6744ba41b47cccb3604e854139d607c6f146e377 100644
--- a/lily/grob-scheme.cc
+++ b/lily/grob-scheme.cc
@@ -26,6 +26,17 @@
 #include "paper-score.hh"
 #include "grob-array.hh"

+LY_DEFINE (ly_grob_hash, "ly:grob-hash",
+          1, 0, 0, (SCM grob),
+          "Return the hash of the grob.")
+{
+  Grob *sc = unsmob_grob (grob);
+
+  LY_ASSERT_SMOB (Grob, grob, 1);
+
+  return scm_from_int (sc->hash ());
+}
+
 LY_DEFINE (ly_grob_property_data, "ly:grob-property-data",
           2, 0, 0, (SCM grob, SCM sym),
           "Return the value for property @var{sym} of @var{grob},"
Index: lily/grob.cc
diff --git a/lily/grob.cc b/lily/grob.cc
index c613effccc65fd6be001aad742e41a1ed29b15a4..8937044b4754b1463797242604adc28d8fe1d43b 100644
--- a/lily/grob.cc
+++ b/lily/grob.cc
@@ -39,6 +39,8 @@

 #include "ly-smobs.icc"

+int Grob::master_hash_ = 0;
+
 Grob *
 Grob::clone () const
 {
@@ -56,7 +58,9 @@ Grob::Grob (SCM basicprops)
   immutable_property_alist_ = basicprops;
   mutable_property_alist_ = SCM_EOL;
   object_alist_ = SCM_EOL;
-
+  hash_ = master_hash_;
+  master_hash_++;
+
   /* We do smobify_self () as the first step.  Since the object lives
      on the heap, none of its SCM variables are protected from
      GC. After smobify_self (), they are.  */
@@ -91,6 +95,8 @@ Grob::Grob (Grob const &s)
   mutable_property_alist_ = ly_deep_copy (s.mutable_property_alist_);
   interfaces_ = s.interfaces_;
   object_alist_ = SCM_EOL;
+  hash_ = master_hash_;
+  master_hash_++;

   layout_ = 0;

@@ -604,6 +610,12 @@ Grob::name () const
   return scm_is_symbol (nm) ? ly_symbol2string (nm) : this->class_name ();
 }

+int
+Grob::hash () const
+{
+  return hash_;
+}
+
 void
 Grob::programming_error (string s) const
 {
Index: lily/include/grob.hh
diff --git a/lily/include/grob.hh b/lily/include/grob.hh
index eda94b6d5888b1778897658c683c7c20c5c57944..d627d1df4b385cf3b2fa4b1cdb4dd1ba5f990ea0 100644
--- a/lily/include/grob.hh
+++ b/lily/include/grob.hh
@@ -32,6 +32,7 @@ private:
   DECLARE_CLASSNAME(Grob);

   void init ();
+  static int master_hash_;

 protected:
   /* data */
@@ -43,7 +44,8 @@ protected:
   SCM immutable_property_alist_;
   SCM mutable_property_alist_;
   SCM object_alist_;
-
+  int hash_;
+
   /*
     If this is a property, it accounts for 25% of the property
     lookups.
@@ -87,6 +89,9 @@ public:
   /* naming. */
   string name () const;

+  /* hashing. */
+  int hash () const;
+
   /* Properties */
   SCM get_property_alist_chain (SCM) const;
   SCM internal_get_property (SCM symbol) const;





reply via email to

[Prev in Thread] Current Thread [Next in Thread]