aboutsummaryrefslogtreecommitdiff
path: root/cores
diff options
context:
space:
mode:
authorMatthijs Kooijman <matthijs@stdin.nl>2014-02-12 19:37:09 +0100
committerMatthijs Kooijman <matthijs@stdin.nl>2014-02-14 10:25:34 +0100
commit02a5ae97d4604f50121f743ae42ab244a9ea49c1 (patch)
tree8c3bf1fe50fcf3a5522a96a87ed7bd82cecf8a3f /cores
parent6c7f786d3de10011c551fba44d40dfd1b59a4985 (diff)
In HardwareSerial, don't use int for buffer indices
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).
Diffstat (limited to 'cores')
-rw-r--r--cores/arduino/HardwareSerial.cpp4
1 files changed, 2 insertions, 2 deletions
diff --git a/cores/arduino/HardwareSerial.cpp b/cores/arduino/HardwareSerial.cpp
index 81b406a..a270ace 100644
--- a/cores/arduino/HardwareSerial.cpp
+++ b/cores/arduino/HardwareSerial.cpp
@@ -171,7 +171,7 @@ int HardwareSerial::read(void)
return -1;
} else {
unsigned char c = _rx_buffer[_rx_buffer_tail];
- _rx_buffer_tail = (unsigned int)(_rx_buffer_tail + 1) % SERIAL_BUFFER_SIZE;
+ _rx_buffer_tail = (uint8_t)(_rx_buffer_tail + 1) % SERIAL_BUFFER_SIZE;
return c;
}
}
@@ -207,7 +207,7 @@ size_t HardwareSerial::write(uint8_t c)
sbi(*_ucsra, TXC0);
return 1;
}
- int i = (_tx_buffer_head + 1) % SERIAL_BUFFER_SIZE;
+ uint8_t i = (_tx_buffer_head + 1) % SERIAL_BUFFER_SIZE;
// If the output buffer is full, there's nothing for it other than to
// wait for the interrupt handler to empty it a bit