From: Kefu Chai Date: Sun, 29 Sep 2019 17:08:52 +0000 (+0800) Subject: common/ceph_time: do not handle negative case X-Git-Tag: v15.1.0~1371^2~4 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=376335c93fad385f8040e1f95684ad7117346856;p=ceph-ci.git 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 --- diff --git a/src/common/ceph_time.cc b/src/common/ceph_time.cc index c44b2eac14d..bb708bb4675 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