Cleanup and (maybe) speedup InsetMathChar::mathClass

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.
This commit is contained in:
Jean-Marc Lasgouttes 2023-07-15 23:26:31 +02:00
parent 99f972e2c4
commit d8e509e5eb

View File

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