What can be done to reduce executable size?
Andrei Alexandrescu
SeeWebsiteForEmail at erdani.org
Fri Dec 16 11:04:39 PST 2011
On 12/16/11 12:40 PM, Jonathan M Davis wrote:
> On Friday, December 16, 2011 11:45:42 Andrei Alexandrescu wrote:
>> I am pretty sure they don't need static this(). Only last night I
>> removed static this() from core.time.
>
> I don't know how you could do that in core.time, since ticksPerSec and
> appOrigin are immutable and have to be set at runtime. How on earth can you do
> that without a static constructor?
>
> std.datetime has the same problem with the added fun of having to avoid
> breaking purity, because the functions for getting the singletons are pure.
This goes back to the issue of lazy initialization. Today you need a
cast to do that. Here's my code:
static @trusted @property long ticksPerSec() pure nothrow
{
return (cast(immutable(long) function() pure nothrow)
&ticksPerSecImpl)();
}
static @property immutable(long) ticksPerSecImpl() nothrow
{
static long result;
if (result)
{
return result;
}
... initialization ...
return result;
}
The presence of the cast is unsightly but the code does something
unusual (modifies what looks from the outside like a constant) so it is
justifiable, particularly since we're talking about the language's core
library.
Andrei
More information about the Digitalmars-d
mailing list