1
0
mirror of https://github.com/arduino/Arduino.git synced 2025-01-19 08:52:15 +01:00

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.
This commit is contained in:
Matthijs Kooijman 2015-12-08 18:57:57 +01:00 committed by Martino Facchin
parent 6715f41c0e
commit 052764fd58

View File

@ -228,21 +228,12 @@ public class SketchData {
}
protected void removeCode(SketchCode which) {
for (SketchCode code : codes) {
if (code == which) {
codes.remove(code);
return;
}
}
System.err.println("removeCode: internal error.. could not find code");
if (!codes.remove(which))
System.err.println("removeCode: internal error.. could not find code");
}
public int indexOfCode(SketchCode who) {
for (SketchCode code : codes) {
if (code == who)
return codes.indexOf(code);
}
return -1;
return codes.indexOf(who);
}
public String getName() {