commit 2db858afebc534335242ac2a4d569458aeb69da1
parent ca2323e4c76bc138b9c5593c1c6d09133a2883e7
Author: cfillion <cfillion@users.noreply.github.com>
Date: Thu, 21 Jan 2016 14:10:44 -0500
avoid concatenating strings when possible
Diffstat:
3 files changed, 12 insertions(+), 16 deletions(-)
diff --git a/src/encoding.hpp b/src/encoding.hpp
@@ -22,6 +22,7 @@
// MultiByteToWideChar is required to make file path like
// "C:\Users\Test\Downloads\Новая папка" work on Windows...
+#include <cstdio>
#include <string>
#ifdef _WIN32
@@ -31,6 +32,7 @@ typedef std::wstring auto_string;
#define AUTO_STR(text) L##text
#define to_autostring std::to_wstring
+#define auto_snprintf _snwprintf
auto_string make_autostring(const std::string &);
std::string from_autostring(const auto_string &);
@@ -41,6 +43,7 @@ typedef std::string auto_string;
#define AUTO_STR(text) text
#define to_autostring std::to_string
+#define auto_snprintf snprintf
#define make_autostring(string) string
#define from_autostring(string) string
diff --git a/src/manager.cpp b/src/manager.cpp
@@ -24,8 +24,6 @@
#include "remote.hpp"
#include "resource.hpp"
-#include <cstdio>
-
using namespace std;
enum { ACTION_ENABLE = 300, ACTION_DISABLE, ACTION_UNINSTALL };
@@ -189,11 +187,7 @@ bool Manager::confirm() const
const size_t uninstallSize = m_uninstall.size();
auto_char msg[255] = {};
-#ifdef _WIN32
- _snwprintf(msg, sizeof(msg),
-#else
- snprintf(msg, sizeof(msg),
-#endif
+ auto_snprintf(msg, sizeof(msg),
AUTO_STR("Uninstall %lu remote%s?\n")
AUTO_STR("Every file they contain will be removed from your computer."),
uninstallSize, uninstallSize == 1 ? AUTO_STR("") : AUTO_STR("s"));
diff --git a/src/progress.cpp b/src/progress.cpp
@@ -90,20 +90,19 @@ void Progress::addDownload(Download *dl)
void Progress::updateProgress()
{
- const auto_string text = AUTO_STR("Downloading ") +
- to_autostring(min(m_done + 1, m_total)) + AUTO_STR(" of ") +
- to_autostring(m_total) + AUTO_STR(": ") + m_currentName;
+ auto_char label[1024] = {};
+ auto_snprintf(label, sizeof(label), AUTO_STR("Downloading %d of %d: %s"),
+ min(m_done + 1, m_total), m_total, m_currentName.c_str());
- SetWindowText(m_label, text.c_str());
+ SetWindowText(m_label, label);
const double pos = (double)m_done / m_total;
const int percent = (int)(pos * 100);
- static const auto_string TITLE = AUTO_STR("ReaPack: Download in progress");
-
- const auto_string title = TITLE +
- AUTO_STR(" (") + to_autostring(percent) + AUTO_STR("%)");
+ auto_char title[255] = {};
+ auto_snprintf(title, sizeof(title),
+ AUTO_STR("ReaPack: Download in progress (%d%%)"), percent);
SendMessage(m_progress, PBM_SETPOS, percent, 0);
- SetWindowText(handle(), title.c_str());
+ SetWindowText(handle(), title);
}