Skip to content

Commit

Permalink
Merge faster time-zone parsing
Browse files Browse the repository at this point in the history
Fixes #282
  • Loading branch information
jodastephen committed Aug 20, 2015
1 parent 027bfdd commit 695c02c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
1 change: 1 addition & 0 deletions RELEASE-NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ This is the same license as all of Apache, plus other open source projects such

Changes in 2.8.3
================
- Faster parsing of time-zone identifiers [#282]


Changes in 2.8.2
Expand Down
4 changes: 4 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@
<name>Luc Claes</name>
<url>https://github.com/lucclaes</url>
</contributor>
<contributor>
<name>Emiliano Claria</name>
<url>https://github.com/emilianogc</url>
</contributor>
<contributor>
<name>Dan Cojocar</name>
<url>https://github.com/dancojocar</url>
Expand Down
14 changes: 9 additions & 5 deletions src/main/java/org/joda/time/format/DateTimeFormatterBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -2313,7 +2313,7 @@ static enum TimeZoneId
implements InternalPrinter, InternalParser {

INSTANCE;
static final List<String> ALL_IDS;
private static final List<String> ALL_IDS;
static {
ALL_IDS = new ArrayList<String>(DateTimeZone.getAvailableIDs());
Collections.sort(ALL_IDS);
Expand Down Expand Up @@ -2354,7 +2354,9 @@ public int parseInto(DateTimeParserBucket bucket, CharSequence text, int positio
if (best == null || id.length() > best.length()) {
best = id;
}
} else break;
} else {
break;
}
}
if (best != null) {
bucket.setZone(DateTimeZone.forID(best));
Expand All @@ -2370,7 +2372,7 @@ private static int prefixedStartPosition(CharSequence text, int position) {
while (lo <= hi) {
int mid = (lo + hi) >>> 1;
String value = ALL_IDS.get(mid);
int compare = csCompare(value, text, position);
int compare = csCompare(text, position, value);
if (compare > 0) {
hi = mid - 1;
} else if (compare < 0) {
Expand Down Expand Up @@ -2614,11 +2616,13 @@ public int parseInto(DateTimeParserBucket bucket, CharSequence text, int positio
}
}

static int csCompare(String search, CharSequence text, int position) {
static int csCompare(CharSequence text, int position, String search) {
int compareLen = Math.min(text.length() - position, search.length());
for (int i = 0; i < compareLen; i++) {
int result = search.charAt(i) - text.charAt(position + i);
if (result != 0) return result;
if (result != 0) {
return result;
}
}
return 0;
}
Expand Down

0 comments on commit 695c02c

Please sign in to comment.