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

Commit

Permalink
Merge pull request #2317 from n8sh/issue-19280-pt2
Browse files Browse the repository at this point in the history
Fix Issue 19280 - Remove unnecessary error checks in core.time, Part 2
merged-on-behalf-of: Jonathan M Davis <jmdavis@users.noreply.github.com>
  • Loading branch information
dlang-bot committed Oct 14, 2018
2 parents 8074173 + 8759cb6 commit 6519311
Showing 1 changed file with 24 additions and 16 deletions.
40 changes: 24 additions & 16 deletions src/core/time.d
Expand Up @@ -2108,26 +2108,26 @@ struct MonoTimeImpl(ClockType clockType)

version (Windows)
{
long ticks;
if (QueryPerformanceCounter(&ticks) == 0)
{
// This probably cannot happen on Windows 95 or later
import core.internal.abort : abort;
abort("Call to QueryPerformanceCounter failed.");
}
long ticks = void;
QueryPerformanceCounter(&ticks);
return MonoTimeImpl(ticks);
}
else version (Darwin)
return MonoTimeImpl(mach_absolute_time());
else version (Posix)
{
timespec ts;
if (clock_gettime(clockArg, &ts) != 0)
timespec ts = void;
immutable error = clock_gettime(clockArg, &ts);
// clockArg is supported and if tv_sec is long or larger
// overflow won't happen before 292 billion years A.D.
static if (ts.tv_sec.max < long.max)
{
import core.internal.abort : abort;
abort("Call to clock_gettime failed.");
if (error)
{
import core.internal.abort : abort;
abort("Call to clock_gettime failed.");
}
}

return MonoTimeImpl(convClockFreq(ts.tv_sec * 1_000_000_000L + ts.tv_nsec,
1_000_000_000L,
ticksPerSecond));
Expand Down Expand Up @@ -3364,10 +3364,18 @@ struct TickDuration
{
static if (is(typeof(clock_gettime)))
{
timespec ts;
if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0)
abort("Failed in clock_gettime().");

timespec ts = void;
immutable error = clock_gettime(CLOCK_MONOTONIC, &ts);
// CLOCK_MONOTONIC is supported and if tv_sec is long or larger
// overflow won't happen before 292 billion years A.D.
static if (ts.tv_sec.max < long.max)
{
if (error)
{
import core.internal.abort : abort;
abort("Call to clock_gettime failed.");
}
}
return TickDuration(ts.tv_sec * TickDuration.ticksPerSec +
ts.tv_nsec * TickDuration.ticksPerSec / 1000 / 1000 / 1000);
}
Expand Down

0 comments on commit 6519311

Please sign in to comment.