Slight improvement to the line parsing logic, saving 8 cycles per character

This commit is contained in:
etagle 2017-08-08 02:57:55 -03:00
parent 534bbb81ff
commit 2864ef8c7f

View File

@ -1094,9 +1094,10 @@ inline void get_serial_commands() {
/** /**
* Loop while serial characters are incoming and the queue is not full * 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 * If the character ends the line
@ -1196,9 +1197,9 @@ inline void get_serial_commands() {
// The command will be injected when EOL is reached // The command will be injected when EOL is reached
} }
else if (serial_char == '\\') { // Handle escapes else if (serial_char == '\\') { // Handle escapes
if (MYSERIAL.available() > 0) { if ((c = MYSERIAL.read()) >= 0) {
// if we have one more character, copy it over // 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; if (!serial_comment_mode) serial_line_buffer[serial_count++] = serial_char;
} }
// otherwise do nothing // otherwise do nothing