Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.

Commit 6519311

Browse files
authored
Merge pull request #2317 from n8sh/issue-19280-pt2
Fix Issue 19280 - Remove unnecessary error checks in core.time, Part 2 merged-on-behalf-of: Jonathan M Davis <jmdavis@users.noreply.github.com>
2 parents 8074173 + 8759cb6 commit 6519311

File tree

1 file changed

+24
-16
lines changed

1 file changed

+24
-16
lines changed

src/core/time.d

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2108,26 +2108,26 @@ struct MonoTimeImpl(ClockType clockType)
21082108

21092109
version (Windows)
21102110
{
2111-
long ticks;
2112-
if (QueryPerformanceCounter(&ticks) == 0)
2113-
{
2114-
// This probably cannot happen on Windows 95 or later
2115-
import core.internal.abort : abort;
2116-
abort("Call to QueryPerformanceCounter failed.");
2117-
}
2111+
long ticks = void;
2112+
QueryPerformanceCounter(&ticks);
21182113
return MonoTimeImpl(ticks);
21192114
}
21202115
else version (Darwin)
21212116
return MonoTimeImpl(mach_absolute_time());
21222117
else version (Posix)
21232118
{
2124-
timespec ts;
2125-
if (clock_gettime(clockArg, &ts) != 0)
2119+
timespec ts = void;
2120+
immutable error = clock_gettime(clockArg, &ts);
2121+
// clockArg is supported and if tv_sec is long or larger
2122+
// overflow won't happen before 292 billion years A.D.
2123+
static if (ts.tv_sec.max < long.max)
21262124
{
2127-
import core.internal.abort : abort;
2128-
abort("Call to clock_gettime failed.");
2125+
if (error)
2126+
{
2127+
import core.internal.abort : abort;
2128+
abort("Call to clock_gettime failed.");
2129+
}
21292130
}
2130-
21312131
return MonoTimeImpl(convClockFreq(ts.tv_sec * 1_000_000_000L + ts.tv_nsec,
21322132
1_000_000_000L,
21332133
ticksPerSecond));
@@ -3364,10 +3364,18 @@ struct TickDuration
33643364
{
33653365
static if (is(typeof(clock_gettime)))
33663366
{
3367-
timespec ts;
3368-
if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0)
3369-
abort("Failed in clock_gettime().");
3370-
3367+
timespec ts = void;
3368+
immutable error = clock_gettime(CLOCK_MONOTONIC, &ts);
3369+
// CLOCK_MONOTONIC is supported and if tv_sec is long or larger
3370+
// overflow won't happen before 292 billion years A.D.
3371+
static if (ts.tv_sec.max < long.max)
3372+
{
3373+
if (error)
3374+
{
3375+
import core.internal.abort : abort;
3376+
abort("Call to clock_gettime failed.");
3377+
}
3378+
}
33713379
return TickDuration(ts.tv_sec * TickDuration.ticksPerSec +
33723380
ts.tv_nsec * TickDuration.ticksPerSec / 1000 / 1000 / 1000);
33733381
}

0 commit comments

Comments
 (0)