[LyX/master] Cleanup and (maybe) speedup InsetMathChar::mathClass
Jean-Marc Lasgouttes
lasgouttes at lyx.org
Sat Jul 15 20:16:25 UTC 2023
commit d8e509e5ebb7890f1f62bf8731cf445782cb6bc2
Author: Jean-Marc Lasgouttes <lasgouttes at lyx.org>
Date: Sat Jul 15 23:26:31 2023 +0200
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.
---
src/mathed/InsetMathChar.cpp | 22 ++++++++++++++++------
1 files changed, 16 insertions(+), 6 deletions(-)
diff --git a/src/mathed/InsetMathChar.cpp b/src/mathed/InsetMathChar.cpp
index d923d04..71aba6f 100644
--- a/src/mathed/InsetMathChar.cpp
+++ b/src/mathed/InsetMathChar.cpp
@@ -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;
+ }
}
More information about the lyx-cvs
mailing list