]> git.lyx.org Git - lyx.git/commitdiff
remove unneeded code
authorAndré Pönitz <poenitz@gmx.net>
Thu, 9 Aug 2001 15:56:38 +0000 (15:56 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Thu, 9 Aug 2001 15:56:38 +0000 (15:56 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2470 a592a061-630c-0410-9148-cb99ea01b6c8

src/mathed/math_hash.C
src/mathed/math_parser.h

index d011174516c752efacca2951d671b4039c347599..3987f3153e70ff75994fdef1328bea2d5c93871c 100644 (file)
@@ -1,14 +1,13 @@
 #include <config.h>
-#include <map>
 
-#include "math_defs.h"
 #include "math_parser.h"
-#include "support/lstrings.h"
-#include <iostream>
+#include <algorithm>
 
 namespace {
 
-latexkeys const wordlist[] = 
+// This lists needs to remain sorted all the time!
+
+latexkeys wordlist[] = 
 {
        //{"displaystyle",  LM_TK_STY, LM_ST_DISPLAY, LMB_NONE},
        //{"oint",  LM_TK_BIGSYM, LM_oint, LMB_NONE},
@@ -302,50 +301,22 @@ latexkeys const wordlist[] =
 };
 
 
-struct symbolindex {
-       unsigned int id;
-       short token;
-
-       symbolindex(unsigned int i, short t) : id(i), token(t)
-       {}
-
-       bool operator<(symbolindex const & s) const
-       {
-               return (id < s.id) || (id == s.id && token < s.token);
-       }
-};
-
+bool operator<(const latexkeys & a, const latexkeys & b)
+{
+       return string(a.name) < string(b.name);
+}
 
-// global maps 
-std::map<symbolindex, int>  LatexkeyById;
-std::map<string, int>       LatexkeyByName;
 
+// the "Initializer": Its default constructor is executed on loading and
+// sorts the list. Not exactly needed as long as the list is kept sorted
+// but who knows...
 
-// 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) {
-                       if (LatexkeyByName.find(it->name) != LatexkeyByName.end()) {
-                               std::cerr << "math_hash.C: Bug: Duplicate entry: " 
-                                         << it->name << std::endl;
-                       }
-                       LatexkeyByName[it->name] = it - wordlist;
-                       if (it->id != 0 && 
-                           LatexkeyById.find(symbolindex(it->id, it->token)) !=
-                           LatexkeyById.end()) {
-                               std::cerr << "math_hash.C: Bug: Duplicate entry: "
-                                         << it->name << " Id: "
-                                         << it->id << " token: " << it->token
-                                         << std::endl;
-                       }
-                       LatexkeyById[symbolindex(it->id, it->token)] = it - wordlist;
-               }
+               std::sort(wordlist, wordlist + sizeof(wordlist)/sizeof(wordlist[0]));
        }
 };
 
-// the "Initializer": Its default constructor is executed on loading and
-// fills the maps
 static init dummy;
 
 } // namespace anon
@@ -353,14 +324,12 @@ static init dummy;
 
 latexkeys const * in_word_set(string const & str)
 {
-       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(unsigned int id, short tc)
-{
-       std::map<symbolindex, int>::const_iterator pos
-               = LatexkeyById.find(symbolindex(id, tc));
-       return pos == LatexkeyById.end() ? 0 : &wordlist[pos->second];
+#ifdef WITH_WARNINGS
+#warning Not nice yet...
+#endif
+       latexkeys tmp;
+       tmp.name = str.c_str();
+       int const n = sizeof(wordlist)/sizeof(wordlist[0]);
+       latexkeys const * pos = std::lower_bound(wordlist, wordlist + n, tmp);
+       return (string(pos->name) == str) ? pos : 0;
 }
index 1e9144a93a9d209746751935def1d8c2ee43e0f2..fa2e929d15eff204f72c3bb393b02807f115fa5e 100644 (file)
@@ -119,10 +119,6 @@ struct latexkeys {
 ///
 latexkeys const * in_word_set(string const & str);
 
-///
-latexkeys const * lm_get_key_by_id(unsigned int id, short tc);
-
-
 MathMatrixInset * mathed_parse_normal(string const &);
 MathMatrixInset * mathed_parse_normal(std::istream &);
 MathMatrixInset * mathed_parse_normal(LyXLex &);