diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/api/FileText.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/api/FileText.java index c61e59608..0b54a9148 100755 --- a/src/checkstyle/com/puppycrawl/tools/checkstyle/api/FileText.java +++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/api/FileText.java @@ -18,11 +18,13 @@ //////////////////////////////////////////////////////////////////////////////// package com.puppycrawl.tools.checkstyle.api; +import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStreamReader; import java.io.Reader; +import java.io.StringReader; import java.io.UnsupportedEncodingException; import java.nio.ByteBuffer; import java.nio.charset.Charset; @@ -30,6 +32,7 @@ import java.nio.charset.CharsetDecoder; import java.nio.charset.CodingErrorAction; import java.nio.charset.UnsupportedCharsetException; import java.util.AbstractList; +import java.util.ArrayList; import java.util.Arrays; import java.util.ConcurrentModificationException; import java.util.List; @@ -81,7 +84,7 @@ public final class FileText extends AbstractList /** * The full text contents of the file. */ - private final CharSequence mFullText; + private final String mFullText; /** * The lines of the file, without terminators. @@ -145,16 +148,20 @@ public final class FileText extends AbstractList // buf.trimToSize(); // could be used instead of toString(). mFullText = buf.toString(); - final String[] lines = LINE_TERMINATOR.split(mFullText, -1); - if (lines.length > 0 && lines[lines.length - 1].length() == 0) { - // drop empty line after last newline - mLines = new String[lines.length - 1]; - System.arraycopy(lines, 0, mLines, 0, lines.length - 1); - } - else { - // no newline at end, so we keep the last line as is - mLines = lines; + // Use the BufferedReader to break down the lines as this + // is about 30% faster than using the + // LINE_TERMINATOR.split(mFullText, -1) method + final ArrayList lines = new ArrayList(); + final BufferedReader br = + new BufferedReader(new StringReader(mFullText)); + for (;;) { + final String l = br.readLine(); + if (null == l) { + break; + } + lines.add(l); } + mLines = lines.toArray(new String[lines.size()]); } /** @@ -178,7 +185,7 @@ public final class FileText extends AbstractList mFile = aFile; mCharset = null; - mFullText = buf; + mFullText = buf.toString(); mLines = aLines.toArray(new String[aLines.size()]); } diff --git a/src/xdocs/releasenotes.xml b/src/xdocs/releasenotes.xml index bd98cd3b4..d95e2e87c 100755 --- a/src/xdocs/releasenotes.xml +++ b/src/xdocs/releasenotes.xml @@ -14,7 +14,7 @@

New features:

  • - Support + Support SuppressWarningsFilter to use @SuppressWarnings annotations to suppress violations. Thanks to Trevor Robinson for patch #156. @@ -29,7 +29,11 @@

    Notes:

    • - Upgraded dependencies to Guava 13.0.1 and JUnit 4.11. + Improved the performance of FileText construction, which + increased file loading times by up to 30%. +
    • +
    • + Upgraded dependencies to Guava 14.0.1 and JUnit 4.11.