From 15d75f7397382e01c710fe3edf2da7f655b40329 Mon Sep 17 00:00:00 2001 From: Jordan Sherer Date: Sat, 14 Jul 2018 18:10:07 -0400 Subject: [PATCH] Try not to allocate every time... --- varicode.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/varicode.cpp b/varicode.cpp index 076e540..1a12df2 100644 --- a/varicode.cpp +++ b/varicode.cpp @@ -461,11 +461,13 @@ QString Varicode::unpackGrid(quint16 value){ return deg2grid(dlong, dlat).left(4); } + +QString directed_cmds("?$@&| "); +QRegularExpression directed_re(R"((?[A-Z0-9/]+):(?[A-Z0-9/]+)(?[?$@&| ]))"); + QString Varicode::packDirectedMessage(const QString &text, int *n){ QString frame; - QString cmds("?$@&| "); - QRegularExpression r(R"((?[A-Z0-9/]+):(?[A-Z0-9/]+)(?[?$@&| ]))"); - auto match = r.match(text); + auto match = directed_re.match(text); if(match.hasMatch()){ QString from = match.captured("from"); QString to = match.captured("to"); @@ -479,7 +481,7 @@ QString Varicode::packDirectedMessage(const QString &text, int *n){ quint8 packed_flag = 0; quint32 packed_from = Varicode::packCallsign(from); quint32 packed_to = Varicode::packCallsign(to); - quint8 packed_cmd = cmds.indexOf(cmd.at(0)); + quint8 packed_cmd = directed_cmds.indexOf(cmd.at(0)); // 3 + 28 + 28 + 5 = 64 auto bits = ( @@ -496,7 +498,6 @@ QString Varicode::packDirectedMessage(const QString &text, int *n){ QStringList Varicode::unpackDirectedMessage(const QString &text){ QStringList unpacked; - QString cmds("?$@&| "); auto bits = Varicode::bitsToStr(Varicode::intToBits(Varicode::unpack64bits(text), 64)); quint8 flag = Varicode::bitsToInt(Varicode::strToBits(bits.left(3))); @@ -506,7 +507,7 @@ QStringList Varicode::unpackDirectedMessage(const QString &text){ unpacked.append(Varicode::unpackCallsign(packed_from).trimmed()); unpacked.append(Varicode::unpackCallsign(packed_to).trimmed()); - unpacked.append(QString(cmds.at(packed_cmd & 5))); + unpacked.append(QString(directed_cmds.at(packed_cmd & 5))); return unpacked; }