From 25696b7fb338f87045154a27e223f896c67c53a4 Mon Sep 17 00:00:00 2001 From: Howard Hinnant Date: Tue, 24 Oct 2017 15:44:41 -0400 Subject: [PATCH] Optimize to_stream for zoned_time * Decrease the number of lookups in the database from 2 to 1. --- include/date/tz.h | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/include/date/tz.h b/include/date/tz.h index 1387bf1b..6d6a2c2f 100644 --- a/include/date/tz.h +++ b/include/date/tz.h @@ -1774,8 +1774,13 @@ std::basic_ostream& to_stream(std::basic_ostream& os, const CharT* fmt, const zoned_time& 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; + using LT = local_time; + 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