lilypond-1.5.9
[lilypond.git] / lily / symbol-cache.cc
blobd247ccd3d577e45d7b401cdc39681b7b98eaebc8
1 /*
2 symbol-cache.cc -- implement a cache for literal symbols, eg
3 symbol ("foo-bar")
6 source file of the GNU LilyPond music typesetter
8 (c) 2000--2001 Han-Wen Nienhuys <hanwen@cs.uu.nl>
12 #include <map>
13 #include "lily-guile.hh"
15 #if 0
17 typedef map<const char*, SCM> Literal_symbol_map;
18 Literal_symbol_map literal_map;
21 SCM
22 symbol (const char*s)
24 Literal_symbol_map::const_iterator i = literal_map.find (s);
25 if (i != literal_map.end ())
26 return (*i).second;
28 SCM sym = gh_symbol2scm ((char*)s);
29 scm_permanent_object (sym);
30 literal_map[s] = sym;
31 return sym;
36 This is a gory trick to cache the value gh_symbol2scm (), without
37 cluttering up the C code with snarf macros.
39 You should *ONLY* use symbol () for arguments that are literal
40 strings!
42 without (wtk1-fugue2)
44 real 0m20.157s
45 user 0m19.800s
46 sys 0m0.140s
48 with: (per file.)
50 real 0m19.284s
51 user 0m18.630s
52 sys 0m0.190s
55 global with STL map
57 real 0m20.616s
58 user 0m19.360s
59 sys 0m0.080s
61 global with binsearch.
63 real 0m19.352s
64 user 0m18.710s
65 sys 0m0.230s
67 local binsearch
69 user 18.8
71 local with binsearch, and other optimizations.
73 17.7
75 #endif