From c5a6a44b55f43448f2a9d68ae296716da47aaf21 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Tue, 20 Sep 2016 13:58:36 +0200 Subject: [PATCH] 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); } } --- app/src/cc/arduino/view/findreplace/FindReplace.java | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/app/src/cc/arduino/view/findreplace/FindReplace.java b/app/src/cc/arduino/view/findreplace/FindReplace.java index 039834286..26282ceeb 100644 --- a/app/src/cc/arduino/view/findreplace/FindReplace.java +++ b/app/src/cc/arduino/view/findreplace/FindReplace.java @@ -314,12 +314,6 @@ public class FindReplace extends javax.swing.JFrame { } } - boolean wrapNeeded = false; - if (wrap && nextIndex == -1) { - // if wrapping, a second chance is ok, start from the end - wrapNeeded = true; - } - if (nextIndex == -1) { // Nothing found on this tab: Search other tabs if required if (searchTabs) { @@ -355,7 +349,7 @@ public class FindReplace extends javax.swing.JFrame { } } - if (wrapNeeded) { + if (wrap) { nextIndex = backwards ? text.lastIndexOf(search) : text.indexOf(search, 0); } }