Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f537b4e

Browse files
authored
[libc++] Avoid template instantiations in the duration aliases (llvm#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) `<algorithm>`, `<atomic>`, `<barrier>`, `<chrono>`, `<condition_variable>`, `<future>`, `<iomanip>`, `<ios>`, `<iostream>`, `<istream>`, `<latch>`, `<locale>`, `<mutex>`, `<ostream>`, `<semaphore>`, `<shared_mutex>`, `<syncstream>` and `<thread>`
1 parent 90c632a commit f537b4e

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

libcxx/include/__chrono/duration.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -291,13 +291,13 @@ typedef duration<long long, nano> nanoseconds;
291291
typedef duration<long long, micro> microseconds;
292292
typedef duration<long long, milli> milliseconds;
293293
typedef duration<long long > seconds;
294-
typedef duration< long, ratio< 60> > minutes;
295-
typedef duration< long, ratio<3600> > hours;
294+
typedef duration<long, ratio<60> > minutes;
295+
typedef duration<long, ratio<60 * 60> > hours;
296296
#if _LIBCPP_STD_VER >= 20
297-
typedef duration< int, ratio_multiply<ratio<24>, hours::period>> days;
298-
typedef duration< int, ratio_multiply<ratio<7>, days::period>> weeks;
299-
typedef duration< int, ratio_multiply<ratio<146097, 400>, days::period>> years;
300-
typedef duration< int, ratio_divide<years::period, ratio<12>>> months;
297+
typedef duration<int, ratio<60 * 60 * 24>> days;
298+
typedef duration<int, ratio<60 * 60 * 24 * 7>> weeks;
299+
typedef duration<int, ratio<static_cast<int>(365.2425 * 60 * 60 * 24)>> years;
300+
typedef duration<int, ratio<static_cast<int>(365.2425 * 60 * 60 * 24) / 12>> months;
301301
#endif
302302
// Duration ==
303303

0 commit comments

Comments
 (0)