From 762131a42516ce98c2b44ad3b3ebba06683d16e7 Mon Sep 17 00:00:00 2001 From: apio Date: Mon, 5 Dec 2022 16:43:52 +0100 Subject: [PATCH] Make more constexpr --- kernel/src/arch/Timer.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/kernel/src/arch/Timer.cpp b/kernel/src/arch/Timer.cpp index 58ce56c7..35599f2c 100644 --- a/kernel/src/arch/Timer.cpp +++ b/kernel/src/arch/Timer.cpp @@ -6,23 +6,22 @@ static u64 timer_ticks = 0; static u64 boot_timestamp; -static int isleap(int year) +static inline constexpr int isleap(int year) { return year % 4 == 0 && (year % 100 != 0 || year % 400 == 0); } -static int make_yday(int year, int month) +static constexpr int make_yday(int year, int month) { - static const short int upto[12] = {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334}; - int yd; + constexpr short int upto[12] = {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334}; - yd = upto[month - 1]; + int yd = upto[month - 1]; if (month > 2 && isleap(year)) yd++; return yd; } // https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap04.html#tag_04_16 -static u64 broken_down_to_unix(u64 year, u64 yday, u64 hour, u64 min, u64 sec) +static constexpr u64 broken_down_to_unix(u64 year, u64 yday, u64 hour, u64 min, u64 sec) { return sec + min * 60 + hour * 3600 + yday * 86400 + (year - 70) * 31536000 + ((year - 69) / 4) * 86400 - ((year - 1) / 100) * 86400 + ((year + 299) / 400) * 86400;