bug 59773: move loop invariants out of for-loop for performance, use for-each instead of for loop when possible

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1756345 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Javen O'Neal 2016-08-15 04:42:31 +00:00
parent 34a6732b01
commit e97b333ea0

View File

@ -257,8 +257,8 @@ public final class PowerPointExtractor extends POIOLE2TextExtractor {
// Comments, if requested and present // Comments, if requested and present
if (getCommentText) { if (getCommentText) {
Comment[] comments = slide.getComments(); Comment[] comments = slide.getComments();
for (int j = 0; j < comments.length; j++) { for (Comment comment : slide.getComments()) {
ret.append(comments[j].getAuthor() + " - " + comments[j].getText() + "\n"); ret.append(comment.getAuthor() + " - " + comment.getText() + "\n");
} }
} }
} }
@ -285,8 +285,8 @@ public final class PowerPointExtractor extends POIOLE2TextExtractor {
} }
for (int i = 0; i < _slides.size(); i++) { for (HSLFSlide slide : _slides) {
HSLFNotes notes = _slides.get(i).getNotes(); HSLFNotes notes = slide.getNotes();
if (notes == null) { if (notes == null) {
continue; continue;
} }
@ -315,16 +315,18 @@ public final class PowerPointExtractor extends POIOLE2TextExtractor {
} }
private void extractTableText(StringBuffer ret, HSLFTable table) { private void extractTableText(StringBuffer ret, HSLFTable table) {
for (int row = 0; row < table.getNumberOfRows(); row++){ final int nrows = table.getNumberOfRows();
for (int col = 0; col < table.getNumberOfColumns(); col++){ final int ncols = table.getNumberOfColumns();
for (int row = 0; row < nrows; row++){
for (int col = 0; col < ncols; col++){
HSLFTableCell cell = table.getCell(row, col); HSLFTableCell cell = table.getCell(row, col);
//defensive null checks; don't know if they're necessary //defensive null checks; don't know if they're necessary
if (cell != null){ if (cell != null){
String txt = cell.getText(); String txt = cell.getText();
txt = (txt == null) ? "" : txt; txt = (txt == null) ? "" : txt;
ret.append(txt); ret.append(txt);
if (col < table.getNumberOfColumns()-1){ if (col < ncols-1){
ret.append("\t"); ret.append('\t');
} }
} }
} }
@ -339,7 +341,7 @@ public final class PowerPointExtractor extends POIOLE2TextExtractor {
for (List<HSLFTextParagraph> lp : paragraphs) { for (List<HSLFTextParagraph> lp : paragraphs) {
ret.append(HSLFTextParagraph.getText(lp)); ret.append(HSLFTextParagraph.getText(lp));
if (ret.length() > 0 && ret.charAt(ret.length()-1) != '\n') { if (ret.length() > 0 && ret.charAt(ret.length()-1) != '\n') {
ret.append("\n"); ret.append('\n');
} }
} }
} }