Andre Poenitz <[EMAIL PROTECTED]> writes:

| That's what I tried first, but somehow the inset got messed up... I'll
| retry anyway.

I wonder if this would be a good idea:

--- math_hash.C Wed Apr 25 17:39:36 2001
+++ math_hash.C.new     Wed Apr 25 17:38:04 2001
@@ -305,32 +305,45 @@
 
 
 // helper structure to initialize the maps on startup:
-struct init {
-       init() {
-               int const n = sizeof(wordlist)/sizeof(wordlist[0]);
-               for (latexkeys const * it = wordlist; it != wordlist + n; ++it)
{
-                       LatexkeyByName[it->name] = it - wordlist;
+struct init_latexkeybyid {
+       init_latexkeybyid() {
+               int const n = sizeof(wordlist) / sizeof(wordlist[0]);
+               latexkeys const * cit = wordlist;
+               latexkeys const * end = wordlist + n;
+               for (; cit != end, ++cit) {
                        LatexkeyById[symbolindex(it->id, it->token)] = it - wordlist;
                }
        }
 };
 
-// the "Initializer": Its default constructor is executed on loading and
-// fills the maps
-static init dummy;
 
+// helper structure to initialize the maps on startup:
+struct init_latexkeybyname {
+       init_latexkeybyname() {
+               int const n = sizeof(wordlist) / sizeof(wordlist[0]);
+               latexkeys const * cit = wordlist;
+               latexkeys const * end = wordlist + n;
+               for (; cit != end, ++cit) {
+                       LatexkeyByName[it->name] = it - wordlist;
+               }
+       }
+};
+
 } // namespace anon
 
 
 latexkeys const * in_word_set(string const & str)
 {
+       static init_latexkeybyname dummy;
+
        std::map<string, int>::const_iterator pos = LatexkeyByName.find(str);
        return pos == LatexkeyByName.end() ? 0 : &wordlist[pos->second];
 }
-
-
+
 latexkeys const * lm_get_key_by_id(int id, short tc)
 {
+       static init_latexkeybyid dymmy;
+
        std::map<symbolindex, int>::const_iterator pos
                = LatexkeyById.find(symbolindex(id, tc));
        return pos == LatexkeyById.end() ? 0 : &wordlist[pos->second];


The actual initialization woll be slower, but the cost will be moved
to runtime instead of init time. And documents/sessions that does not
use math at all will not be penalized.

-- 
        Lgb

Reply via email to