AK: Annotate AK::Time APIs as [[nodiscard]]

This commit is contained in:
Brian Gianforcaro 2021-08-14 15:11:14 -07:00 committed by Andreas Kling
parent dae17ce7e3
commit 3cbc2364a8
Notes: sideshowbarker 2024-07-18 05:41:13 +09:00

View file

@ -121,27 +121,27 @@ private:
}
public:
constexpr static Time from_seconds(i64 seconds) { return Time(seconds, 0); }
constexpr static Time from_nanoseconds(i64 nanoseconds)
[[nodiscard]] constexpr static Time from_seconds(i64 seconds) { return Time(seconds, 0); }
[[nodiscard]] constexpr static Time from_nanoseconds(i64 nanoseconds)
{
i64 seconds = sane_mod(nanoseconds, 1'000'000'000);
return Time(seconds, nanoseconds);
}
constexpr static Time from_microseconds(i64 microseconds)
[[nodiscard]] constexpr static Time from_microseconds(i64 microseconds)
{
i64 seconds = sane_mod(microseconds, 1'000'000);
return Time(seconds, microseconds * 1'000);
}
constexpr static Time from_milliseconds(i64 milliseconds)
[[nodiscard]] constexpr static Time from_milliseconds(i64 milliseconds)
{
i64 seconds = sane_mod(milliseconds, 1'000);
return Time(seconds, milliseconds * 1'000'000);
}
static Time from_timespec(const struct timespec&);
static Time from_timeval(const struct timeval&);
constexpr static Time min() { return Time(-0x8000'0000'0000'0000LL, 0); };
constexpr static Time zero() { return Time(0, 0); };
constexpr static Time max() { return Time(0x7fff'ffff'ffff'ffffLL, 999'999'999); };
[[nodiscard]] static Time from_timespec(const struct timespec&);
[[nodiscard]] static Time from_timeval(const struct timeval&);
[[nodiscard]] constexpr static Time min() { return Time(-0x8000'0000'0000'0000LL, 0); };
[[nodiscard]] constexpr static Time zero() { return Time(0, 0); };
[[nodiscard]] constexpr static Time max() { return Time(0x7fff'ffff'ffff'ffffLL, 999'999'999); };
#ifndef KERNEL
[[nodiscard]] static Time now_realtime();
@ -151,19 +151,19 @@ public:
#endif
// Truncates towards zero (2.8s to 2s, -2.8s to -2s).
i64 to_truncated_seconds() const;
i64 to_truncated_milliseconds() const;
i64 to_truncated_microseconds() const;
[[nodiscard]] i64 to_truncated_seconds() const;
[[nodiscard]] i64 to_truncated_milliseconds() const;
[[nodiscard]] i64 to_truncated_microseconds() const;
// Rounds away from zero (2.3s to 3s, -2.3s to -3s).
i64 to_seconds() const;
i64 to_milliseconds() const;
i64 to_microseconds() const;
i64 to_nanoseconds() const;
timespec to_timespec() const;
[[nodiscard]] i64 to_seconds() const;
[[nodiscard]] i64 to_milliseconds() const;
[[nodiscard]] i64 to_microseconds() const;
[[nodiscard]] i64 to_nanoseconds() const;
[[nodiscard]] timespec to_timespec() const;
// Rounds towards -inf (it was the easiest to implement).
timeval to_timeval() const;
[[nodiscard]] timeval to_timeval() const;
bool is_zero() const { return !m_seconds && !m_nanoseconds; }
[[nodiscard]] bool is_zero() const { return !m_seconds && !m_nanoseconds; }
bool operator==(const Time& other) const { return this->m_seconds == other.m_seconds && this->m_nanoseconds == other.m_nanoseconds; }
bool operator!=(const Time& other) const { return !(*this == other); }
@ -183,7 +183,7 @@ private:
{
}
static Time from_half_sanitized(i64 seconds, i32 extra_seconds, u32 nanoseconds);
[[nodiscard]] static Time from_half_sanitized(i64 seconds, i32 extra_seconds, u32 nanoseconds);
i64 m_seconds { 0 };
u32 m_nanoseconds { 0 }; // Always less than 1'000'000'000