Skip to content

Commit

Permalink
Optimize to_stream for zoned_time
Browse files Browse the repository at this point in the history
* Decrease the number of lookups in the database from 2 to 1.
  • Loading branch information
HowardHinnant committed Oct 24, 2017
1 parent 9381e89 commit 25696b7
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions include/date/tz.h
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down

0 comments on commit 25696b7

Please sign in to comment.