2 symbol-cache.hh -- declare Symbol cacher.
4 source file of the GNU LilyPond music typesetter
6 (c) 2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
10 #ifndef SYMBOL_CACHE_HH
11 #define SYMBOL_CACHE_HH
16 A per file cache: for each compilation unit, there is a separate
17 cache that maps the address of a string directly to a SCM value
20 struct Symbol_cache_pair{
25 static Symbol_cache_pair *private_symbol_cache;
26 static Symbol_cache_pair *private_symbol_cache_end;
29 symbol (const char *ch) __attribute__ ((unused));
32 symbol (const char *ch)
34 Symbol_cache_pair * lo = private_symbol_cache;
35 Symbol_cache_pair * hi = private_symbol_cache_end -1;
41 Symbol_cache_pair * mid = lo + (hi - lo) / 2 ;
47 while ((hi - lo) > 1);
53 Symbol_cache_pair * p = private_symbol_cache;
54 for (; p < private_symbol_cache_end
58 int idx = p - private_symbol_cache;
60 SCM sym = gh_symbol2scm ((char*) ch);
61 scm_permanent_object (sym);
63 int sz = private_symbol_cache_end - private_symbol_cache;
66 = (Symbol_cache_pair*) realloc (private_symbol_cache,
67 sizeof (Symbol_cache_pair)* sz);
68 private_symbol_cache_end = private_symbol_cache + sz;
69 for (p = private_symbol_cache_end -1;
70 p != private_symbol_cache + idx; p --)
78 #endif /* SYMBOL_CACHE_HH */