]> source.dussan.org Git - poi.git/commitdiff
bug 59773: move loop invariants out of for-loop for performance, use for-each instead...
authorJaven O'Neal <onealj@apache.org>
Mon, 15 Aug 2016 04:42:31 +0000 (04:42 +0000)
committerJaven O'Neal <onealj@apache.org>
Mon, 15 Aug 2016 04:42:31 +0000 (04:42 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1756345 13f79535-47bb-0310-9956-ffa450edef68

src/scratchpad/src/org/apache/poi/hslf/extractor/PowerPointExtractor.java

index f248ab633db487c42ecf84524e7c7c762d3a3d55..43c7d69bb1b50aebb5ec636ad91a1822d4dde552 100644 (file)
@@ -257,8 +257,8 @@ public final class PowerPointExtractor extends POIOLE2TextExtractor {
                                // Comments, if requested and present
                                if (getCommentText) {
                                        Comment[] comments = slide.getComments();
-                                       for (int j = 0; j < comments.length; j++) {
-                                               ret.append(comments[j].getAuthor() + " - " + comments[j].getText() + "\n");
+                                       for (Comment comment : slide.getComments()) {
+                                               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++) {
-                               HSLFNotes notes = _slides.get(i).getNotes();
+                       for (HSLFSlide slide : _slides) {
+                               HSLFNotes notes = slide.getNotes();
                                if (notes == null) {
                                        continue;
                                }
@@ -297,13 +297,13 @@ public final class PowerPointExtractor extends POIOLE2TextExtractor {
                                seenNotes.add(id);
 
                                // Repeat the Notes header, if set
-                           ret.append(headerText);
+                               ret.append(headerText);
 
                                // Notes text
-                textRunsToText(ret, notes.getTextParagraphs());
+                               textRunsToText(ret, notes.getTextParagraphs());
 
                                // Repeat the notes footer, if set
-                ret.append(footerText);
+                               ret.append(footerText);
                        }
                }
 
@@ -315,16 +315,18 @@ public final class PowerPointExtractor extends POIOLE2TextExtractor {
        }
 
     private void extractTableText(StringBuffer ret, HSLFTable table) {
-        for (int row = 0; row < table.getNumberOfRows(); row++){
-            for (int col = 0; col < table.getNumberOfColumns(); col++){
+        final int nrows = table.getNumberOfRows();
+        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);
                 //defensive null checks; don't know if they're necessary
                 if (cell != null){
                     String txt = cell.getText();
                     txt = (txt == null) ? "" : txt;
                     ret.append(txt);
-                    if (col < table.getNumberOfColumns()-1){
-                        ret.append("\t");
+                    if (col < ncols-1){
+                        ret.append('\t');
                     }
                 }
             }
@@ -339,7 +341,7 @@ public final class PowerPointExtractor extends POIOLE2TextExtractor {
         for (List<HSLFTextParagraph> lp : paragraphs) {
             ret.append(HSLFTextParagraph.getText(lp));
             if (ret.length() > 0 && ret.charAt(ret.length()-1) != '\n') {
-                ret.append("\n");
+                ret.append('\n');
             }
         }
     }