]> git.lyx.org Git - lyx.git/commitdiff
Cleanup and (maybe) speedup InsetMathChar::mathClass
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Sat, 15 Jul 2023 21:26:31 +0000 (23:26 +0200)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Sat, 15 Jul 2023 21:29:24 +0000 (23:29 +0200)
Profiling with hotspot show that it counts for more than it should and
indeed using support::contains is a overkill here. I like the new code
better anyway.

I would be surprised to see that it makes a big difference, though.

src/mathed/InsetMathChar.cpp

index d923d04dc033e3c891f97ad1df51367070e4392a..71aba6f6f770a01c3965ce1370c5d806c80eb02a 100644 (file)
@@ -26,7 +26,6 @@
 #include "frontends/FontMetrics.h"
 
 #include "support/debug.h"
-#include "support/lstrings.h"
 #include "support/textutils.h"
 
 #include <algorithm>
@@ -310,16 +309,27 @@ void InsetMathChar::htmlize(HtmlStream & ms) const
 MathClass InsetMathChar::mathClass() const
 {
        // this information comes from fontmath.ltx in LaTeX source.
-       char const ch = static_cast<char>(char_);
        if (subst_)
                return string_to_class(subst_->extra);
-       else if (support::contains(",;", ch))
+
+       if (!isASCII(char_))
+               return MC_ORD;
+
+       switch (static_cast<char>(char_)) {
+       case ',':
+       case ';':
                return MC_PUNCT;
-       else if (support::contains("([", ch))
+       case '(':
+       case '[':
                return MC_OPEN;
-       else if (support::contains(")]!?", ch))
+       case ')':
+       case ']':
+       case '!':
+       case '?':
                return MC_CLOSE;
-       else return MC_ORD;
+       default:
+               return MC_ORD;
+       }
 }