]> git.donarmstrong.com Git - lilypond.git/blob - lily/profile.cc
Doc-es: various updates.
[lilypond.git] / lily / profile.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 2005--2015 Han-Wen Nienhuys <hanwen@xs4all.nl>
5
6   LilyPond is free software: you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation, either version 3 of the License, or
9   (at your option) any later version.
10
11   LilyPond is distributed in the hope that it will be useful,
12   but WITHOUT ANY WARRANTY; without even the implied warranty of
13   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   GNU General Public License for more details.
15
16   You should have received a copy of the GNU General Public License
17   along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include "profile.hh"
21 #include "protected-scm.hh"
22
23 Protected_scm context_property_lookup_table;
24 Protected_scm grob_property_lookup_table;
25 Protected_scm prob_property_lookup_table;
26
27 LY_DEFINE (ly_property_lookup_stats, "ly:property-lookup-stats",
28            1, 0, 0, (SCM sym),
29            "Return hash table with a property access corresponding to"
30            " @var{sym}.  Choices are @code{prob}, @code{grob}, and"
31            " @code{context}.")
32 {
33   if (context_property_lookup_table.is_bound ()
34       && scm_is_eq (sym, ly_symbol2scm ("context")))
35     return context_property_lookup_table;
36   if (prob_property_lookup_table.is_bound ()
37       && scm_is_eq (sym, ly_symbol2scm ("prob")))
38     return prob_property_lookup_table;
39   if (grob_property_lookup_table.is_bound ()
40       && scm_is_eq (sym, ly_symbol2scm ("grob")))
41     return grob_property_lookup_table;
42   return scm_c_make_hash_table (1);
43 }
44
45 void
46 note_property_access (Protected_scm *table, SCM sym)
47 {
48   /*
49     Statistics: which properties are looked up?
50   */
51   if (!table->is_bound ())
52     *table = scm_c_make_hash_table (259);
53
54   SCM hashhandle = scm_hashq_get_handle (*table, sym);
55   if (scm_is_false (hashhandle))
56     {
57       scm_hashq_set_x (*table, sym, scm_from_int (0));
58       hashhandle = scm_hashq_get_handle (*table, sym);
59     }
60
61   int count = scm_to_int (scm_cdr (hashhandle)) + 1;
62   scm_set_cdr_x (hashhandle, scm_from_int (count));
63 }