Skip to content

Commit 8860630

Browse files
authored
Merge pull request #1759 from brenuart/gh1754
Reuse Calendar instance during parsing
2 parents b308e29 + 28334b7 commit 8860630

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

src/main/java/com/fasterxml/jackson/databind/util/StdDateFormat.java

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -432,14 +432,7 @@ public StringBuffer format(Date date, StringBuffer toAppendTo,
432432
protected void _format(TimeZone tz, Locale loc, Date date,
433433
StringBuffer buffer)
434434
{
435-
Calendar cal = _calendar;
436-
if (cal == null ) {
437-
_calendar = cal = (Calendar)CALENDAR.clone();
438-
}
439-
if (!cal.getTimeZone().equals(tz) ) {
440-
cal.setTimeZone(tz);
441-
}
442-
// Note: Calendar locale not updated since we don't need it here...
435+
Calendar cal = _getCalendar(tz);
443436
cal.setTime(date);
444437

445438
pad4(buffer, cal.get(Calendar.YEAR));
@@ -605,10 +598,7 @@ protected Date _parseAsISO8601(String dateStr, ParsePosition bogus)
605598
if ((_timezone != null) && ('Z' != dateStr.charAt(totalLen-1))) {
606599
tz = _timezone;
607600
}
608-
Calendar cal = new GregorianCalendar(tz, _locale);
609-
if (_lenient != null) {
610-
cal.setLenient(_lenient.booleanValue());
611-
}
601+
Calendar cal = _getCalendar(tz);
612602
String formatStr;
613603
if (totalLen <= 10) {
614604
Matcher m = PATTERN_PLAIN.matcher(dateStr);
@@ -757,6 +747,20 @@ protected void _clearFormats() {
757747
_formatRFC1123 = null;
758748
}
759749

750+
protected Calendar _getCalendar(TimeZone tz) {
751+
Calendar cal = _calendar;
752+
if (cal == null ) {
753+
_calendar = cal = (Calendar)CALENDAR.clone();
754+
}
755+
if (!cal.getTimeZone().equals(tz) ) {
756+
cal.setTimeZone(tz);
757+
}
758+
cal.setLenient(isLenient());
759+
cal.clear();
760+
761+
return cal;
762+
}
763+
760764
protected static <T> boolean _equals(T value1, T value2) {
761765
if (value1 == value2) {
762766
return true;

0 commit comments

Comments
 (0)