Date: prev next · Thread: first prev next last
2011 Archives by date, by thread · List index


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

Attachment: pgpL10VDO8zwc.pgp
Description: PGP signature


Context


Privacy Policy | Impressum (Legal Info) | Copyright information: Unless otherwise specified, all text and images on this website are licensed under the Creative Commons Attribution-Share Alike 3.0 License. This does not include the source code of LibreOffice, which is licensed under the Mozilla Public License (MPLv2). "LibreOffice" and "The Document Foundation" are registered trademarks of their corresponding registered owners or are in actual use as trademarks in one or more countries. Their respective logos and icons are also subject to international copyright laws. Use thereof is explained in our trademark policy.