From f537b4e51822b19780386e0575ff95e82f8ec445 Mon Sep 17 00:00:00 2001 From: Nikolas Klauser Date: Wed, 4 Feb 2026 10:26:48 +0100 Subject: [PATCH] [libc++] Avoid template instantiations in the duration aliases (#178182) These templates are instantiated whenever `<__chrono/duration.h>` is included, making these calculations quite costly. I also don't think that folding the calculations decreases readability here (IMO it's actually easier to read now), so I don't think there is a reason we shouldn't do this. `<__chrono/duration.h>` is currently (transitively) included in at least (I stopped checking) ``, ``, ``, ``, ``, ``, ``, ``, ``, ``, ``, ``, ``, ``, ``, ``, `` and `` --- libcxx/include/__chrono/duration.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/libcxx/include/__chrono/duration.h b/libcxx/include/__chrono/duration.h index 9313fc797ecd..b7762bd1203a 100644 --- a/libcxx/include/__chrono/duration.h +++ b/libcxx/include/__chrono/duration.h @@ -291,13 +291,13 @@ typedef duration nanoseconds; typedef duration microseconds; typedef duration milliseconds; typedef duration seconds; -typedef duration< long, ratio< 60> > minutes; -typedef duration< long, ratio<3600> > hours; +typedef duration > minutes; +typedef duration > hours; #if _LIBCPP_STD_VER >= 20 -typedef duration< int, ratio_multiply, hours::period>> days; -typedef duration< int, ratio_multiply, days::period>> weeks; -typedef duration< int, ratio_multiply, days::period>> years; -typedef duration< int, ratio_divide>> months; +typedef duration> days; +typedef duration> weeks; +typedef duration(365.2425 * 60 * 60 * 24)>> years; +typedef duration(365.2425 * 60 * 60 * 24) / 12>> months; #endif // Duration ==