Fix constexpr of gregorian::date::date(special_values) to improve perf (#214)

GCC up to at least 10.2 fail to resolve
gregorian::date::date(special_values) as constexpr function due to
assignment to *this within the constructor. Refactoring constructor to
initialize the instance once leads to large performance improvement.
This commit is contained in:
Povilas Kanapickas
2022-08-01 13:34:36 +03:00
committed by GitHub
parent 0aed920bfb
commit b81ed2874f

View File

@@ -74,18 +74,8 @@ namespace gregorian {
{}
//! Constructor for infinities, not a date, max and min date
BOOST_CXX14_CONSTEXPR explicit date(special_values sv):
date_time::date<date, gregorian_calendar, date_duration>(date_rep_type::from_special(sv))
{
if (sv == min_date_time)
{
*this = date(1400, 1, 1);
}
if (sv == max_date_time)
{
*this = date(9999, 12, 31);
}
}
date_time::date<date, gregorian_calendar, date_duration>(from_special_adjusted(sv))
{}
//!Return the Julian Day number for the date.
BOOST_CXX14_CONSTEXPR date_int_type julian_day() const
{
@@ -129,6 +119,15 @@ namespace gregorian {
private:
BOOST_CXX14_CONSTEXPR date_rep_type from_special_adjusted(special_values sv)
{
switch (sv)
{
case min_date_time: return gregorian_calendar::day_number(ymd_type(1400, 1, 1));
case max_date_time: return gregorian_calendar::day_number(ymd_type(9999, 12, 31));
default: return date_rep_type::from_special(sv);
}
}
};
inline BOOST_CXX14_CONSTEXPR