Skip to content

Commit b6ba4b6

Browse files
In SoftwareSerial::recv, only calculate the new tail once
This shortens the generated code a bit more.
1 parent 03f242b commit b6ba4b6

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

libraries/SoftwareSerial/SoftwareSerial.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,11 +259,12 @@ void SoftwareSerial::recv()
259259
d = ~d;
260260

261261
// if buffer full, set the overflow flag and return
262-
if ((_receive_buffer_tail + 1) % _SS_MAX_RX_BUFF != _receive_buffer_head)
262+
uint8_t next = (_receive_buffer_tail + 1) % _SS_MAX_RX_BUFF;
263+
if (next != _receive_buffer_head)
263264
{
264265
// save new data in buffer: tail points to where byte goes
265266
_receive_buffer[_receive_buffer_tail] = d; // save new byte
266-
_receive_buffer_tail = (_receive_buffer_tail + 1) % _SS_MAX_RX_BUFF;
267+
_receive_buffer_tail = next;
267268
}
268269
else
269270
{

0 commit comments

Comments
 (0)