bug 59432: move loop invariants outside the loop to marginally improve code execution speed

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1748832 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Javen O'Neal 2016-06-17 11:06:58 +00:00
parent be7fd6ffb6
commit 21e8ce5979

View File

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