Skip to content

Commit a403c19

Browse files
committed
Cast to encourage optimization of Serial ring buffer index calculations.
http://code.google.com/p/arduino/issues/detail?id=391
1 parent 66755f9 commit a403c19

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

hardware/arduino/cores/arduino/HardwareSerial.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ struct ring_buffer
6565

6666
inline void store_char(unsigned char c, ring_buffer *rx_buffer)
6767
{
68-
int i = (rx_buffer->head + 1) % RX_BUFFER_SIZE;
68+
int i = (unsigned int)(rx_buffer->head + 1) % RX_BUFFER_SIZE;
6969

7070
// if we should be storing the received character into the location
7171
// just before the tail (meaning that the head would advance to the
@@ -231,7 +231,7 @@ void HardwareSerial::end()
231231

232232
int HardwareSerial::available(void)
233233
{
234-
return (RX_BUFFER_SIZE + _rx_buffer->head - _rx_buffer->tail) % RX_BUFFER_SIZE;
234+
return (unsigned int)(RX_BUFFER_SIZE + _rx_buffer->head - _rx_buffer->tail) % RX_BUFFER_SIZE;
235235
}
236236

237237
int HardwareSerial::peek(void)
@@ -250,7 +250,7 @@ int HardwareSerial::read(void)
250250
return -1;
251251
} else {
252252
unsigned char c = _rx_buffer->buffer[_rx_buffer->tail];
253-
_rx_buffer->tail = (_rx_buffer->tail + 1) % RX_BUFFER_SIZE;
253+
_rx_buffer->tail = (unsigned int)(_rx_buffer->tail + 1) % RX_BUFFER_SIZE;
254254
return c;
255255
}
256256
}

0 commit comments

Comments
 (0)