From 2864ef8c7f6e06240a648b4ab827d67c1cd26443 Mon Sep 17 00:00:00 2001 From: etagle Date: Tue, 8 Aug 2017 02:57:55 -0300 Subject: [PATCH] Slight improvement to the line parsing logic, saving 8 cycles per character --- Marlin/Marlin_main.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index af16c9500..9d5963054 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -1094,9 +1094,10 @@ inline void get_serial_commands() { /** * Loop while serial characters are incoming and the queue is not full */ - while (commands_in_queue < BUFSIZE && MYSERIAL.available() > 0) { + int c; + while (commands_in_queue < BUFSIZE && (c = MYSERIAL.read()) >= 0) { - char serial_char = MYSERIAL.read(); + char serial_char = c; /** * If the character ends the line @@ -1196,9 +1197,9 @@ inline void get_serial_commands() { // The command will be injected when EOL is reached } else if (serial_char == '\\') { // Handle escapes - if (MYSERIAL.available() > 0) { + if ((c = MYSERIAL.read()) >= 0) { // if we have one more character, copy it over - serial_char = MYSERIAL.read(); + serial_char = c; if (!serial_comment_mode) serial_line_buffer[serial_count++] = serial_char; } // otherwise do nothing