Skip to content

Commit 052764f

Browse files
matthijskooijmanfacchinm
authored andcommitted
Simplify SketchData.removeCode() and indexOfCode()
These used to iterate over the list of SketchCodes to find the right one, and if so, let the List do the same again to remove it or find the index. This can be simplified to just let list take care of things instead. Technically, there is a small difference, since `List.remove()` and `List.indexOf()` will check using `equals()`, while the original code used `==`, but these should be effectively the same here. Also, the original code first used `==` to see if the object was present and then let List find it again using `equals()`, so that was a bit inconsistent anyway.
1 parent 6715f41 commit 052764f

File tree

1 file changed

+3
-12
lines changed

1 file changed

+3
-12
lines changed

arduino-core/src/processing/app/SketchData.java

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -228,21 +228,12 @@ public SketchCode getCode(int i) {
228228
}
229229

230230
protected void removeCode(SketchCode which) {
231-
for (SketchCode code : codes) {
232-
if (code == which) {
233-
codes.remove(code);
234-
return;
235-
}
236-
}
237-
System.err.println("removeCode: internal error.. could not find code");
231+
if (!codes.remove(which))
232+
System.err.println("removeCode: internal error.. could not find code");
238233
}
239234

240235
public int indexOfCode(SketchCode who) {
241-
for (SketchCode code : codes) {
242-
if (code == who)
243-
return codes.indexOf(code);
244-
}
245-
return -1;
236+
return codes.indexOf(who);
246237
}
247238

248239
public String getName() {

0 commit comments

Comments
 (0)