From 376335c93fad385f8040e1f95684ad7117346856 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Mon, 30 Sep 2019 01:08:52 +0800 Subject: [PATCH] common/ceph_time: do not handle negative case this change partially reverts 353a0e5f, unlike `signedspan`, `timespan::rep` is unsigned. so no need to handle negative case. Signed-off-by: Kefu Chai --- src/common/ceph_time.cc | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/common/ceph_time.cc b/src/common/ceph_time.cc index c44b2eac14da..bb708bb46756 100644 --- a/src/common/ceph_time.cc +++ b/src/common/ceph_time.cc @@ -97,24 +97,19 @@ namespace ceph { const std::chrono::time_point& t) { return m << std::fixed << std::chrono::duration( t.time_since_epoch()).count() - << "s"; + << 's'; } std::ostream& operator<<(std::ostream& m, const timespan& t) { - int64_t ns = t.count(); - if (ns < 0) { - ns = -ns; - m << "-"; - } - m << (ns / 1000000000ll); - ns %= 1000000000ll; - if (ns) { + static_assert(std::is_unsigned_v); + m << std::chrono::duration_cast(t).count(); + if (auto ns = (t % 1s).count(); ns > 0) { char oldfill = m.fill(); m.fill('0'); m << '.' << std::setw(9) << ns; m.fill(oldfill); } - return m << "s"; + return m << 's'; } template