From d97ab53cc4bc6db409a2287f633d273ed8930347 Mon Sep 17 00:00:00 2001 From: Javen O'Neal Date: Mon, 15 Aug 2016 04:42:31 +0000 Subject: [PATCH] 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 --- .../hslf/extractor/PowerPointExtractor.java | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/scratchpad/src/org/apache/poi/hslf/extractor/PowerPointExtractor.java b/src/scratchpad/src/org/apache/poi/hslf/extractor/PowerPointExtractor.java index f248ab633d..43c7d69bb1 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/extractor/PowerPointExtractor.java +++ b/src/scratchpad/src/org/apache/poi/hslf/extractor/PowerPointExtractor.java @@ -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 lp : paragraphs) { ret.append(HSLFTextParagraph.getText(lp)); if (ret.length() > 0 && ret.charAt(ret.length()-1) != '\n') { - ret.append("\n"); + ret.append('\n'); } } } -- 2.39.5