[threeten-dev] Minor performance tuning for LocalDate.of(int, int, int)
Stephen Colebourne
scolebourne at joda.org
Thu Mar 7 02:20:03 PST 2013
The patch is fine. I think I would have created a new private method
create(int,int,int) that took in y/m/d that have been validated:
public static LocalDate of(int year, Month month, int dayOfMonth) {
YEAR.checkValidValue(year);
Objects.requireNonNull(month, "month");
DAY_OF_MONTH.checkValidValue(dayOfMonth);
return create(year, month.getValue(), dayOfMonth);
}
public static LocalDate of(int year, int month, int dayOfMonth) {
YEAR.checkValidValue(year);
MONTH_OF_YEAR.checkValidValue(month);
DAY_OF_MONTH.checkValidValue(dayOfMonth);
return create(year,month,day)
}
Mainly to avoid duplicated code. I suspect its smaller bytecode size
and better to hotspot.
You're free to push existing patch or amended one.
Stephen
On 6 March 2013 23:46, Xueming Shen <xueming.shen at oracle.com> wrote:
>
> (1) LocalDate.of(int, int, int)
> appears to create a use-and-throw "Month" object for validation purse
> only, it can be "saved" with a hard-coded Month.length, something
> worth
> doing? given we are talking about "immutable" LD date type and assume
> new objects would be frequently "created" instead of "mutated".
>
> (2) LocalDate.ofYearDay(int, int)
> LocalDate.resolvePreviousValid(int, int, int)
> Shouldn't they just call new LocalDate(year, month, day)?
> all fields have been validated already, it is unnecessary to go
> of()->create()-> new LocalDate()
>
> Here is the proposed update, opinion?
>
> http://cr.openjdk.java.net/~sherman/jdk8_threeten/ldPerm/
>
> -Sherman
>
>
More information about the threeten-dev
mailing list