]> source.dussan.org Git - poi.git/commitdiff
bug 59432: move loop invariants outside the loop to marginally improve code execution...
authorJaven O'Neal <onealj@apache.org>
Fri, 17 Jun 2016 11:06:58 +0000 (11:06 +0000)
committerJaven O'Neal <onealj@apache.org>
Fri, 17 Jun 2016 11:06:58 +0000 (11:06 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1748832 13f79535-47bb-0310-9956-ffa450edef68

src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFName.java

index be68c3050075910169e2046ece33af43f3b669e1..1e592514ad2eccb66ded057af03486c1aa8e50ae 100644 (file)
@@ -167,15 +167,15 @@ public final class XSSFName implements Name {
         validateName(name);
 
         int sheetIndex = getSheetIndex();
-
-        //Check to ensure no other names have the same case-insensitive name
-        for (int i = 0; i < _workbook.getNumberOfNames(); i++) {
+        int numberOfNames = _workbook.getNumberOfNames();
+        //Check to ensure no other names have the same case-insensitive name at the same scope
+        for (int i = 0; i < numberOfNames; i++) {
             XSSFName nm = _workbook.getNameAt(i);
-            if (nm != this) {
-                if(name.equalsIgnoreCase(nm.getNameName()) && sheetIndex == nm.getSheetIndex()){
-                    String msg = "The "+(sheetIndex == -1 ? "workbook" : "sheet")+" already contains this name: " + name;
-                    throw new IllegalArgumentException(msg);
-               }
+            if ((nm != this)
+                    && name.equalsIgnoreCase(nm.getNameName())
+                    && (sheetIndex == nm.getSheetIndex())) {
+                String msg = "The "+(sheetIndex == -1 ? "workbook" : "sheet")+" already contains this name: " + name;
+                throw new IllegalArgumentException(msg);
             }
         }
         _ctName.setName(name);