Skip to content

Commit c5a6a44

Browse files
committed
Simplify FindReplace.find() logic (part 2)
The snippet: boolean wrapNeeded = false; if (wrap && nextIndex == -1) { // if wrapping, a second chance is ok, start from the end wrapNeeded = true; } Can be moved inside the `if (nextIndex == -1)` that follows, this way: if (nextIndex == -1) { boolean wrapNeeded = false; if (wrap) { // if wrapping, a second chance is ok, start from the end wrapNeeded = true; } [...CUT...] if (wrapNeeded) { nextIndex = backwards ? text.lastIndexOf(search) : text.indexOf(search, 0); } } but since `wrapNeeded` is used only at the very end of the `if` statement we can move it forward: if (nextIndex == -1) { [...CUT...] boolean wrapNeeded = false; if (wrap) { // if wrapping, a second chance is ok, start from the end wrapNeeded = true; } if (wrapNeeded) { nextIndex = backwards ? text.lastIndexOf(search) : text.indexOf(search, 0); } } and finally simplify it by removing `wrapNeeded` altogether: if (nextIndex == -1) { [...CUT...] if (wrap) { nextIndex = backwards ? text.lastIndexOf(search) : text.indexOf(search, 0); } }
1 parent 47fcff7 commit c5a6a44

File tree

1 file changed

+1
-7
lines changed

1 file changed

+1
-7
lines changed

app/src/cc/arduino/view/findreplace/FindReplace.java

+1-7
Original file line numberDiff line numberDiff line change
@@ -314,12 +314,6 @@ private boolean find(boolean wrap, boolean backwards, boolean searchTabs, int or
314314
}
315315
}
316316

317-
boolean wrapNeeded = false;
318-
if (wrap && nextIndex == -1) {
319-
// if wrapping, a second chance is ok, start from the end
320-
wrapNeeded = true;
321-
}
322-
323317
if (nextIndex == -1) {
324318
// Nothing found on this tab: Search other tabs if required
325319
if (searchTabs) {
@@ -355,7 +349,7 @@ private boolean find(boolean wrap, boolean backwards, boolean searchTabs, int or
355349
}
356350
}
357351

358-
if (wrapNeeded) {
352+
if (wrap) {
359353
nextIndex = backwards ? text.lastIndexOf(search) : text.indexOf(search, 0);
360354
}
361355
}

0 commit comments

Comments
 (0)