summaryrefslogtreecommitdiffstats
path: root/regex
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2010-04-09 23:36:48 -0700
committerElliott Hughes <enh@google.com>2010-04-09 23:46:25 -0700
commit601555d9c55a78a3d4aefdf8f50645545b8ab484 (patch)
tree9531f2246ef00a27dc219beed9c04c59bee3b772 /regex
parent0510f0d8ce7c20b8f6022545a70e8b868805dc60 (diff)
downloadlibcore-601555d9c55a78a3d4aefdf8f50645545b8ab484.zip
libcore-601555d9c55a78a3d4aefdf8f50645545b8ab484.tar.gz
libcore-601555d9c55a78a3d4aefdf8f50645545b8ab484.tar.bz2
Fix build by turning a comment into a doc comment. Clarify logic.
Now I see what jessewilson was trying to say earlier; rewrite the post-loop code to say what I guess it was aiming at, which is avoiding an add followed by a remove in the not completely uncommon case where limit == 0 and the regular expression is a terminator rather than a true separator ('\n', say). (Normally the regular expression is a true separator so there will be no trailing empty string even though limit is 0: "a,b,c".split(","), for example.) Also, String.isEmpty is our fasest way of recognizing the empty string; certainly better than equals(""). Change-Id: I82f4ec49fa58efc178e342cf55d4dfbbdad01c75
Diffstat (limited to 'regex')
-rw-r--r--regex/src/main/java/java/util/regex/Splitter.java18
1 files changed, 8 insertions, 10 deletions
diff --git a/regex/src/main/java/java/util/regex/Splitter.java b/regex/src/main/java/java/util/regex/Splitter.java
index 5b4c048..d30bada 100644
--- a/regex/src/main/java/java/util/regex/Splitter.java
+++ b/regex/src/main/java/java/util/regex/Splitter.java
@@ -19,7 +19,7 @@ package java.util.regex;
import java.util.ArrayList;
import java.util.List;
-/*
+/**
* Used to make {@code String.split} fast (and to help {@code Pattern.split} too).
* @hide
*/
@@ -100,18 +100,16 @@ public class Splitter {
}
private static String[] finishSplit(List<String> list, String input, int begin, int maxSize, int limit) {
- // Add trailing text if enough space.
- if (list.size() < maxSize) {
- if (begin < input.length()) {
- list.add(input.substring(begin));
- } else {
- list.add("");
- }
+ // Add trailing text.
+ if (begin < input.length()) {
+ list.add(input.substring(begin));
+ } else if (limit != 0) { // No point adding the empty string if limit == 0, just to remove it below.
+ list.add("");
}
- // Remove trailing empty matches in the limit == 0 case.
+ // Remove all trailing empty matches in the limit == 0 case.
if (limit == 0) {
int i = list.size() - 1;
- while (i >= 0 && "".equals(list.get(i))) {
+ while (i >= 0 && list.get(i).isEmpty()) {
list.remove(i);
i--;
}