-
Notifications
You must be signed in to change notification settings - Fork 82
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cache formatter with offset parsed #120
Merged
cowtowncoder
merged 1 commit into
FasterXML:2.12
from
guidomedina:cache-formatter-with-offset-parsed
Dec 20, 2020
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,8 @@ public class JacksonJodaDateFormat extends JacksonJodaFormatBase | |
|
||
protected final DateTimeFormatter _formatter; | ||
|
||
protected final DateTimeFormatter _formatterWithOffsetParsed; | ||
|
||
protected final TimeZone _jdkTimezone; | ||
|
||
protected transient DateTimeZone _jodaTimezone; | ||
|
@@ -47,6 +49,7 @@ public JacksonJodaDateFormat(DateTimeFormatter defaultFormatter) | |
{ | ||
super(); | ||
_formatter = defaultFormatter; | ||
_formatterWithOffsetParsed = _formatter.withOffsetParsed(); | ||
DateTimeZone tz = defaultFormatter.getZone(); | ||
_jdkTimezone = (tz == null) ? null : tz.toTimeZone(); | ||
_explicitTimezone = false; | ||
|
@@ -59,6 +62,7 @@ public JacksonJodaDateFormat(JacksonJodaDateFormat base, | |
{ | ||
super(base, useTimestamp); | ||
_formatter = base._formatter; | ||
_formatterWithOffsetParsed = _formatter.withOffsetParsed(); | ||
_jdkTimezone = base._jdkTimezone; | ||
_explicitTimezone = base._explicitTimezone; | ||
_adjustToContextTZOverride = base._adjustToContextTZOverride; | ||
|
@@ -70,6 +74,7 @@ public JacksonJodaDateFormat(JacksonJodaDateFormat base, | |
{ | ||
super(base); | ||
_formatter = formatter; | ||
_formatterWithOffsetParsed = _formatter.withOffsetParsed(); | ||
_jdkTimezone = base._jdkTimezone; | ||
_explicitTimezone = base._explicitTimezone; | ||
_adjustToContextTZOverride = base._adjustToContextTZOverride; | ||
|
@@ -80,6 +85,7 @@ public JacksonJodaDateFormat(JacksonJodaDateFormat base, TimeZone jdkTimezone) | |
{ | ||
super(base, jdkTimezone); | ||
_formatter = base._formatter.withZone(DateTimeZone.forTimeZone(jdkTimezone)); | ||
_formatterWithOffsetParsed = _formatter.withOffsetParsed(); | ||
_jdkTimezone = jdkTimezone; | ||
_explicitTimezone = true; | ||
_adjustToContextTZOverride = base._adjustToContextTZOverride; | ||
|
@@ -90,6 +96,7 @@ public JacksonJodaDateFormat(JacksonJodaDateFormat base, Locale locale) | |
{ | ||
super(base, locale); | ||
_formatter = base._formatter.withLocale(locale); | ||
_formatterWithOffsetParsed = _formatter.withOffsetParsed(); | ||
_jdkTimezone = base._jdkTimezone; | ||
_explicitTimezone = base._explicitTimezone; | ||
_adjustToContextTZOverride = base._adjustToContextTZOverride; | ||
|
@@ -104,6 +111,7 @@ protected JacksonJodaDateFormat(JacksonJodaDateFormat base, | |
{ | ||
super(base); | ||
_formatter = base._formatter; | ||
_formatterWithOffsetParsed = _formatter.withOffsetParsed(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can also just copy? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same reason as my previous comment. |
||
_jdkTimezone = base._jdkTimezone; | ||
_explicitTimezone = base._explicitTimezone; | ||
_adjustToContextTZOverride = adjustToContextTZOverride; | ||
|
@@ -255,20 +263,20 @@ public DateTimeFormatter createFormatterWithLocale(SerializerProvider ctxt) | |
public DateTimeFormatter createParser(DeserializationContext ctxt) | ||
{ | ||
DateTimeFormatter formatter = _formatter; | ||
if (!_explicitLocale) { | ||
Locale loc = ctxt.getLocale(); | ||
if (loc != null && !loc.equals(_locale)) { | ||
formatter = formatter.withLocale(loc); | ||
} | ||
} | ||
if (!_explicitTimezone) { | ||
if (shouldAdjustToContextTimeZone(ctxt)) { | ||
TimeZone tz = ctxt.getTimeZone(); | ||
if (tz != null && !tz.equals(_jdkTimezone)) { | ||
formatter = formatter.withZone(DateTimeZone.forTimeZone(tz)); | ||
} | ||
} else { | ||
formatter = formatter.withOffsetParsed(); | ||
formatter = _formatterWithOffsetParsed; | ||
} | ||
} | ||
if (!_explicitLocale) { | ||
Locale loc = ctxt.getLocale(); | ||
if (loc != null && !loc.equals(_locale)) { | ||
formatter = formatter.withLocale(loc); | ||
} | ||
} | ||
return formatter; | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This probably could just be
base._formatterWithOffsetParsed
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason for this vanilla copy & paste is just in case
_formatter
is changed to something else in the future, so that you don't have to also maintain the value at_formatterWithOffsetParsed
The idea is, whatever is assigned to
_formatter
, create a with offset parsed version of exactly that.Do let me know if the reason I stated justifies it, if you still don't agree I will change it to what you have suggested.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't have strong feelings here -- seems like avoiding another operation would be nice, but then again this is not in the hot codepath (as (de)serializer that uses it is cached). So I'll trust your judgment with it.