[Libreoffice] [ANNOUNCE] Date, Time and DateTime default ctors are gone
Eike Rathke
erack at redhat.com
Thu Dec 1 12:07:05 PST 2011
Hi,
To get rid of unnecessary calls to quite expensive system's get
localtime due to the mad implementation of the Date,Time,DateTime
default ctors that call localtime_r() (*ix,Linux) or GetLocalTime()
(Windows) each I reworked the entire code base.
Date,Time,DateTime default ctors are now dead. Instead there are:
class Date {
enum DateInitSystem { SYSTEM };
Date(DateInitSystem);
enum DateInitEmpty { EMPTY };
Date(DateInitEmpty);
};
class Time {
enum TimeInitSystem { SYSTEM };
Time(TimeInitSystem);
enum TimeInitEmpty { EMPTY };
Time(TimeInitEmpty);
};
class DateTime {
enum DateTimeInitSystem { SYSTEM };
DateTime(DateTimeInitSystem);
enum DateTimeInitEmpty { EMPTY };
DateTime(DateTimeInitEmpty);
};
So to init with system time you now need to call
Date(Date::SYSTEM), Time(Time::SYSTEM) or DateTime(DateTime::SYSTEM)
To init empty respectively with 0, which is equivalent, you have to use
Date(Date::EMPTY) or Date(0), Time(Time::EMPTY) or Time(0), or
DateTime(DateTime::EMPTY) (there's no DateTime(0) equivalent) if you
want to init without localtime calls. This to not accidentally
reintroduce default ctors in new code that assumes localtime init.
In case new code using default ctors was committed now after this change
the build would break with no Date::Date(), Time::Time() or
DateTime::DateTime() found.
I carefully inspected doubtful places and where uncertain used the
conservative approach of *::SYSTEM instead of *::EMPTY, but very few
occurrences may have slipped my attention and accidentally been replaced
by *::EMPTY instead. You may want to check your area for correctness
anyway, just grep for '(Date|Time|DateTime)::(SYSTEM|EMPTY)'
After a while we might replace all *::EMPTY usage with new default ctors
again, on the other hand that might not be a good idea if we want to
merge AOOo code that does not have this change.
What do we gain?
Previously:
~350 places that called Date,Time,DateTime default ctor, resulting in
calls to localtime each, actually even two of these calls for DateTime.
Now:
Replaced ~130 (of which ~40 are in binfilter so not quite important)
occurrences to not call localtime anymore. As quite a number of them are
in mass objects or called massively for bookkeeping things and
reinitialized with updated values after having been constructed just to
declare a variable, I expect to have gotten rid of a gazillion of calls
to localtime with this change. Sorry, no real numbers on that.
Have a happy Time :)
Eike
--
LibreOffice Calc developer. Number formatter stricken i18n transpositionizer.
GnuPG key 0x293C05FD : 997A 4C60 CE41 0149 0DB3 9E96 2F1A D073 293C 05FD
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/libreoffice/attachments/20111201/ed98cd53/attachment.pgp>
More information about the LibreOffice
mailing list