diff --git a/DCCWaveform.cpp b/DCCWaveform.cpp
index 8344995..42d4661 100644
--- a/DCCWaveform.cpp
+++ b/DCCWaveform.cpp
@@ -17,6 +17,7 @@
* You should have received a copy of the GNU General Public License
* along with CommandStation. If not, see .
*/
+ #pragma GCC optimize ("-O3")
#include
#include "DCCWaveform.h"
@@ -198,7 +199,10 @@ void DCCWaveform::interrupt2() {
}
else if (packetPending) {
// Copy pending packet to transmit packet
- for (int b = 0; b < pendingLength; b++) transmitPacket[b] = pendingPacket[b];
+ // a fixed length memcpy is faster than a variable length loop for these small lengths
+ // for (int b = 0; b < pendingLength; b++) transmitPacket[b] = pendingPacket[b];
+ memcpy( transmitPacket, pendingPacket, sizeof(pendingPacket));
+
transmitLength = pendingLength;
transmitRepeats = pendingRepeats;
packetPending = false;
@@ -223,7 +227,7 @@ void DCCWaveform::schedulePacket(const byte buffer[], byte byteCount, byte repea
while (packetPending);
byte checksum = 0;
- for (int b = 0; b < byteCount; b++) {
+ for (byte b = 0; b < byteCount; b++) {
checksum ^= buffer[b];
pendingPacket[b] = buffer[b];
}
diff --git a/DCCWaveform.h b/DCCWaveform.h
index 8f82678..890ba49 100644
--- a/DCCWaveform.h
+++ b/DCCWaveform.h
@@ -29,7 +29,7 @@ const int POWER_SAMPLE_OVERLOAD_WAIT = 20;
// Number of preamble bits.
const int PREAMBLE_BITS_MAIN = 16;
const int PREAMBLE_BITS_PROG = 22;
-const byte MAX_PACKET_SIZE = 12;
+const byte MAX_PACKET_SIZE = 5; // NMRA standard exrtended packets
// The WAVE_STATE enum is deliberately numbered because a change of order would be catastrophic
// to the transform array.