Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 8bf8bdf

Browse files
matthijskooijmancmaglie
authored andcommittedMar 24, 2020
Use Math.min instead of ternary if in Serial data copy
This makes the code slightly more compact and easier to read.
1 parent a1027f8 commit 8bf8bdf

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed
 

‎arduino-core/src/processing/app/Serial.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,7 @@ public void processSerialEvent(byte[] buf) {
191191
int next = 0;
192192
while(next < buf.length) {
193193
while(next < buf.length && outToMessage.hasRemaining()) {
194-
int spaceInIn = inFromSerial.remaining();
195-
int copyNow = buf.length - next < spaceInIn ? buf.length - next : spaceInIn;
194+
int copyNow = Math.min(buf.length - next, inFromSerial.remaining());
196195
inFromSerial.put(buf, next, copyNow);
197196
next += copyNow;
198197
inFromSerial.flip();

0 commit comments

Comments
 (0)
Please sign in to comment.