Optimize to_stream for zoned_time

* Decrease the number of lookups in the database from 2 to 1.
This commit is contained in:
Howard Hinnant 2017-10-24 15:44:41 -04:00
parent 9381e894a5
commit 25696b7fb3

View File

@ -1774,8 +1774,13 @@ std::basic_ostream<CharT, Traits>&
to_stream(std::basic_ostream<CharT, Traits>& os, const CharT* fmt,
const zoned_time<Duration, TimeZonePtr>& tp)
{
auto const info = tp.get_info();
return to_stream(os, fmt, tp.get_local_time(), &info.abbrev, &info.offset);
using duration = typename zoned_time<Duration, TimeZonePtr>::duration;
using LT = local_time<duration>;
auto const tz = tp.get_time_zone();
auto const st = tp.get_sys_time();
auto const info = tz->get_info(st);
return to_stream(os, fmt, LT{(st+info.offset).time_since_epoch()},
&info.abbrev, &info.offset);
}
template <class CharT, class Traits, class Duration, class TimeZonePtr>