1
0
mirror of https://github.com/arduino/Arduino.git synced 2025-01-21 10:52:14 +01:00

Use Math.min instead of ternary if in Serial data copy

This makes the code slightly more compact and easier to read.
This commit is contained in:
Matthijs Kooijman 2020-02-26 18:38:08 +01:00 committed by Cristian Maglie
parent d6667dd4ca
commit d244a45c4a

View File

@ -191,8 +191,7 @@ public class Serial implements SerialPortEventListener {
int next = 0;
while(next < buf.length) {
while(next < buf.length && outToMessage.hasRemaining()) {
int spaceInIn = inFromSerial.remaining();
int copyNow = buf.length - next < spaceInIn ? buf.length - next : spaceInIn;
int copyNow = Math.min(buf.length - next, inFromSerial.remaining());
inFromSerial.put(buf, next, copyNow);
next += copyNow;
inFromSerial.flip();