classpath-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [cp-patches] GregorianCalendar mess


From: Jeroen Frijters
Subject: RE: [cp-patches] GregorianCalendar mess
Date: Thu, 14 Oct 2004 10:20:33 +0200

Bryce McKinlay wrote:
> We need to find a way to avoid the "new int[]" in calculateTime(), as 
> this is a pretty substantial performance regression.

Yeah, I didn't like it either. There is also getDayOfYear() that
allocates a temporary array that feels like a waste. I don't see an
obvious way to fix it though (and keep the code readable).

> Perhaps a separate pass to normalize the fields is needed,
> which can be called by both calculateDay() and computeTime()?

The nasty thing about this class is that all of its state is protected,
so subclasses could (theoretically) depend on all sorts of nasty
implementation details. I don't know if we should care about such a
theoretical scenario, but it bothers me never the less.

> I think this could also simplify much of the other code, since it
> can assume the fields are already properly rolled over after each
> set() call, etc?

That doesn't work. The docs explicitly say that set doesn't do anything
other than setting that particular field and the result of roll over
depends on the contents of the other fields. For example, the follow
code should print two identical dates:

GregorianCalendar cal = new GregorianCalendar();

cal.set(Calendar.MONTH, Calendar.FEBRUARY);
cal.set(Calendar.DAY_OF_MONTH, 31);
cal.set(Calendar.MONTH, Calendar.MARCH);
System.out.println(cal.getTime());

cal.set(Calendar.MONTH, Calendar.MARCH);
cal.set(Calendar.DAY_OF_MONTH, 31);
cal.set(Calendar.MONTH, Calendar.MARCH);
System.out.println(cal.getTime());

> Thanks for working on this!

Thanks for reviewing my changes.

Regards,
Jeroen




reply via email to

[Prev in Thread] Current Thread [Next in Thread]