33#include " mainwindow.h"
44
55#include < QtWidgets/QApplication>
6+ #include < QStringView>
7+ #include < QtCore/QLatin1StringView>
8+
9+ #include < algorithm>
10+ #include < array>
11+
12+
13+ using namespace Qt ::StringLiterals;
14+
15+ namespace {
16+ inline constexpr std::array controlFlowMnemonics {
17+ " CALL" _L1, " DJNZ" _L1, " JP" _L1, " JR" _L1, " RET" _L1, " RETI" _L1, " RETN" _L1, " RST" _L1
18+ };
19+
20+ inline constexpr std::array noTargetMnemonics {
21+ " RET" _L1, " RETI" _L1, " RETN" _L1
22+ };
23+
24+ inline constexpr std::array reservedTokens {
25+ " A" _L1, " B" _L1, " C" _L1, " D" _L1, " E" _L1, " H" _L1, " L" _L1, " I" _L1, " R" _L1,
26+ " AF" _L1, " BC" _L1, " DE" _L1, " HL" _L1, " SP" _L1,
27+ " IX" _L1, " IY" _L1, " IXH" _L1, " IXL" _L1,
28+ " IYH" _L1, " IYL" _L1, " MB" _L1,
29+ " NZ" _L1, " Z" _L1, " NC" _L1, " C" _L1,
30+ " PO" _L1, " PE" _L1, " P" _L1, " M" _L1
31+ };
32+ }
633
734DataWidget::DataWidget (QWidget *parent) : QPlainTextEdit{parent} {
835 moveable = false ;
@@ -193,7 +220,11 @@ void AsmHighlighter::highlightBlock(const QString &text) {
193220
194221 const QString fullMnemonic = match.captured (6 );
195222 const QString primary = fullMnemonic.section (' .' , 0 , 0 ).toUpper ();
196- const bool isControlFlow = std::find (controlFlowMnemonics.begin (), controlFlowMnemonics.end (), primary.toStdString ()) != controlFlowMnemonics.end ();
223+ const QStringView pv{primary};
224+
225+ const bool isControlFlow = std::any_of (controlFlowMnemonics.begin (), controlFlowMnemonics.end (),
226+ [&](const QLatin1StringView tok){ return pv == tok; });
227+
197228 if (isControlFlow) {
198229 setFormat (match.capturedStart (6 ), match.capturedLength (6 ), controlFlowFormat);
199230 }
@@ -212,7 +243,8 @@ void AsmHighlighter::highlightBlock(const QString &text) {
212243 return ;
213244 }
214245
215- if (std::find (noTargetMnemonics.begin (), noTargetMnemonics.end (), primary.toStdString ()) != noTargetMnemonics.end ()) {
246+ if (std::any_of (noTargetMnemonics.begin (), noTargetMnemonics.end (),
247+ [&](const QLatin1StringView tok){ return pv == tok; })) {
216248 return ;
217249 }
218250
@@ -239,7 +271,8 @@ void AsmHighlighter::highlightBlock(const QString &text) {
239271 const auto m3 = lIt.next ();
240272 if (m3.hasMatch ()) {
241273 const QString tok = m3.captured ().toUpper ();
242- if (std::find (reservedTokens.begin (), reservedTokens.end (), tok.toStdString ()) != reservedTokens.end ()) {
274+ if (std::any_of (reservedTokens.begin (), reservedTokens.end (),
275+ [&](const QLatin1StringView t){ return tok == t; })) {
243276 continue ;
244277 }
245278 const int start = operandStart + m3.capturedStart ();
0 commit comments