From cbb4b4b318ea5dbcdf1e3f3d87e532558612ad8d Mon Sep 17 00:00:00 2001 From: Nomango <569629550@qq.com> Date: Fri, 1 Feb 2019 23:12:57 +0800 Subject: [PATCH] optimize --- src/core/ActionGroup.h | 2 +- src/core/Task.h | 8 ++++---- src/core/logs.cpp | 11 +++++------ 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/core/ActionGroup.h b/src/core/ActionGroup.h index e2925d79..afcdd712 100644 --- a/src/core/ActionGroup.h +++ b/src/core/ActionGroup.h @@ -30,7 +30,7 @@ namespace easy2d public: explicit Loop( ActionPtr const& action, /* 执行循环的动作 */ - int times = -1 /* 循环次数 */ + int times = -1 /* 循环次数 */ ); virtual ~Loop(); diff --git a/src/core/Task.h b/src/core/Task.h index 12411f29..7b3cc62c 100644 --- a/src/core/Task.h +++ b/src/core/Task.h @@ -40,14 +40,14 @@ namespace easy2d public: explicit Task( - Callback const& func, /* 执行函数 */ + Callback const& func, /* 执行函数 */ String const& name = L"" /* 任务名称 */ ); explicit Task( - Callback const& func, /* 执行函数 */ - Duration delay, /* 时间间隔(秒) */ - int times = -1, /* 执行次数(设 -1 为永久执行) */ + Callback const& func, /* 执行函数 */ + Duration delay, /* 时间间隔(秒) */ + int times = -1, /* 执行次数(设 -1 为永久执行) */ String const& name = L"" /* 任务名称 */ ); diff --git a/src/core/logs.cpp b/src/core/logs.cpp index 3fe6607f..ada96ec5 100644 --- a/src/core/logs.cpp +++ b/src/core/logs.cpp @@ -100,15 +100,16 @@ namespace easy2d if (!enabled) return; + static wchar_t temp_buffer[1024 * 3 + 1]; + size_t len = ::_vscwprintf(format, args) + 1; - wchar_t* buffer = new wchar_t[len]; - ::_vsnwprintf_s(buffer, len, len, format, args); + ::_vsnwprintf_s(temp_buffer, len, len, format, args); std::wstringstream ss; if (prompt) - ss << OutPrefix << prompt << buffer; + ss << OutPrefix << prompt << temp_buffer; else - ss << OutPrefix << buffer; + ss << OutPrefix << temp_buffer; if (endl) ss << L"\r\n"; @@ -116,8 +117,6 @@ namespace easy2d std::wstring output = ss.str(); os << color << output; ::OutputDebugStringW(output.c_str()); - - delete[] buffer; } }