From c165db986b8ecec28c31452fe90d36819a1d3768 Mon Sep 17 00:00:00 2001 From: Haibo Date: Mon, 7 Jan 2019 23:51:01 +0800 Subject: [PATCH] optimize --- core/base/Node.h | 2 +- core/base/time.cpp | 14 +++++++------- core/base/time.h | 8 ++++---- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/core/base/Node.h b/core/base/Node.h index b377bad3..c4ebbb26 100644 --- a/core/base/Node.h +++ b/core/base/Node.h @@ -120,7 +120,7 @@ namespace easy2d float GetOpacity() const { return opacity_; } // 获取变换 - Transform const& GetTransform() const { return transform_; } + Transform const& GetTransform() const { return transform_; } // 获取包围盒 Rect GetBounds() const; diff --git a/core/base/time.cpp b/core/base/time.cpp index 30ac1637..beb109a0 100644 --- a/core/base/time.cpp +++ b/core/base/time.cpp @@ -35,7 +35,7 @@ namespace easy2d { } - TimePoint::TimePoint(const Duration& dur) + TimePoint::TimePoint(long long dur) : dur(dur) { } @@ -52,29 +52,29 @@ namespace easy2d const TimePoint TimePoint::operator+(const Duration & dur) const { - return TimePoint(dur + dur); + return TimePoint{ (dur + dur).Milliseconds() }; } const TimePoint TimePoint::operator-(const Duration & dur) const { - return TimePoint(dur - dur); + return TimePoint{ (dur - dur).Milliseconds() }; } TimePoint & TimePoint::operator+=(const Duration & other) { - dur += other; + dur += other.Milliseconds(); return (*this); } TimePoint & TimePoint::operator-=(const Duration &other) { - dur -= other; + dur -= other.Milliseconds(); return (*this); } const Duration TimePoint::operator-(const TimePoint & other) const { - return dur - other.dur; + return Duration{ dur - other.dur }; } TimePoint& TimePoint::operator=(const TimePoint & other) E2D_NOEXCEPT @@ -449,7 +449,7 @@ namespace easy2d const long long whole = (count.QuadPart / freq.QuadPart) * 1000LL; const long long part = (count.QuadPart % freq.QuadPart) * 1000LL / freq.QuadPart; - return TimePoint{ Duration{ whole + part } }; + return TimePoint{ whole + part }; } Duration easy2d::time::ParseDuration(const std::wstring & str) diff --git a/core/base/time.h b/core/base/time.h index a41d12d1..fa7b0584 100644 --- a/core/base/time.h +++ b/core/base/time.h @@ -44,7 +44,7 @@ namespace easy2d public: Duration(); - Duration( + explicit Duration( long long milliseconds ); @@ -147,7 +147,7 @@ namespace easy2d TimePoint(); explicit TimePoint( - const Duration& + long long ); TimePoint( @@ -159,7 +159,7 @@ namespace easy2d ); // 是否是零时 - inline bool IsZero() const { return dur.IsZero(); } + inline bool IsZero() const { return dur == 0; } const TimePoint operator + (const Duration &) const; const TimePoint operator - (const Duration &) const; @@ -173,7 +173,7 @@ namespace easy2d TimePoint& operator = (TimePoint &&) E2D_NOEXCEPT; private: - Duration dur; + long long dur; }; // 获取当前时间