Skip to content

Commit 45b5aa3

Browse files
In HardwareSerial::_rx_complete_irq, don't use int for buffer index
This was already fixed for HardwareSerial.cpp in #1863, but there was one more case hidden in HardwareSerial_private.h. The index attributes have been uint8_t for a while, so there is no point in using int for local variables. This should allow the compiler to generate slightly more efficient code, but (at least on gcc 4.8.2) it also confuses the register allocator, causing this change to increase code size by 2 bytes instead due to extra push/pop instructions (but this will probably change in the future if the compiler improves).
1 parent f4cd0ff commit 45b5aa3

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

Diff for: cores/arduino/HardwareSerial_private.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ void HardwareSerial::_rx_complete_irq(void)
9999
// No Parity error, read byte and store it in the buffer if there is
100100
// room
101101
unsigned char c = *_udr;
102-
int i = (unsigned int)(_rx_buffer_head + 1) % SERIAL_BUFFER_SIZE;
102+
uint8_t i = (unsigned int)(_rx_buffer_head + 1) % SERIAL_BUFFER_SIZE;
103103

104104
// if we should be storing the received character into the location
105105
// just before the tail (meaning that the head would advance to the

0 commit comments

Comments
 (0)