Skip to content

Commit 0558a35

Browse files
committed
Optimisation from Ortwin Glueck (#SANDBOX-166) in which empty String arrays are replaced with constants.
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/sandbox/csv/trunk@430240 13f79535-47bb-0310-9956-ffa450edef68
1 parent d7dc07f commit 0558a35

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

src/java/org/apache/commons/csv/CSVUtils.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
*/
2525
public class CSVUtils {
2626

27+
private static final String[] EMPTY_STRING_ARRAY = new String[0];
28+
private static final String[][] EMPTY_DOUBLE_STRING_ARRAY = new String[0][0];
29+
2730
/**
2831
* <p><code>CSVUtils</code> instances should NOT be constructed in
2932
* standard programming.
@@ -86,7 +89,7 @@ public static String[][] parse(String s) throws IOException {
8689
if (result == null) {
8790
// since CSVStrategy ignores empty lines an empty array is returned
8891
// (i.e. not "result = new String[][] {{""}};")
89-
result = new String[0][0];
92+
result = EMPTY_DOUBLE_STRING_ARRAY;
9093
}
9194
return result;
9295
}
@@ -108,7 +111,7 @@ public static String[] parseLine(String s) throws IOException {
108111
}
109112
// uh,jh: make sure that parseLine("").length == 0
110113
if (s.length() == 0) {
111-
return new String[0];
114+
return EMPTY_STRING_ARRAY;
112115
}
113116
return (new CSVParser(new StringReader(s))).getLine();
114117
}

0 commit comments

Comments
 (0)