From 008c5795c07a8ca51daa0c777ac40615431f35cd Mon Sep 17 00:00:00 2001 From: Tindy X <49061470+tindy2013@users.noreply.github.com> Date: Sun, 26 Jul 2020 19:21:12 +0800 Subject: [PATCH] Fix some bad implementations Optimize codes. --- src/ini_reader.h | 4 ++-- src/misc.h | 2 +- src/speedtestutil.cpp | 12 ++++++++++++ 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/ini_reader.h b/src/ini_reader.h index fe04616..bb4f486 100644 --- a/src/ini_reader.h +++ b/src/ini_reader.h @@ -5,7 +5,7 @@ #include #include #include -#include +#include #include "misc.h" @@ -800,7 +800,7 @@ public: template int SetArray(const std::string §ion, std::string itemName, const std::string &separator, T &Array) { std::string data; - std::transform(std::begin(Array), std::end(Array), std::back_inserter(data), [&](auto x) { return std::to_string(x) + separator; }); + data = std::accumulate(std::begin(Array), std::end(Array), std::string(), [&](auto a, auto b) { return std::move(a) + std::to_string(b) + separator; }); data.erase(data.size() - 1); return Set(section, std::move(itemName), data); } diff --git a/src/misc.h b/src/misc.h index a22de37..34c9cd2 100644 --- a/src/misc.h +++ b/src/misc.h @@ -163,7 +163,7 @@ public: template tribool(const T &value) { set(value); } - explicit tribool(const tribool &value) { *this = value; } + tribool(const tribool &value) { *this = value; } ~tribool() = default; diff --git a/src/speedtestutil.cpp b/src/speedtestutil.cpp index 8e35e14..489e043 100644 --- a/src/speedtestutil.cpp +++ b/src/speedtestutil.cpp @@ -175,6 +175,7 @@ void explodeVmessConf(std::string content, const std::string &custom_port, bool node.port = to_int(port, 1); node.proxyStr = vmessConstruct(node.group, node.remarks, add, port, type, id, aid, net, cipher, path, host, edge, tls, udp, tfo, scv); nodes.emplace_back(std::move(node)); + node = nodeInfo(); } return; } @@ -250,6 +251,7 @@ void explodeVmessConf(std::string content, const std::string &custom_port, bool node.server = add; node.port = to_int(port, 1); nodes.emplace_back(std::move(node)); + node = nodeInfo(); } return; } @@ -381,6 +383,7 @@ void explodeSSD(std::string link, bool libev, const std::string &custom_port, st node.proxyStr = ssConstruct(group, remarks, server, port, password, method, plugin, pluginopts, libev); node.id = index; nodes.emplace_back(std::move(node)); + node = nodeInfo(); index++; } return; @@ -424,6 +427,7 @@ void explodeSSAndroid(std::string ss, bool libev, const std::string &custom_port node.port = to_int(port, 1); node.proxyStr = ssConstruct(group, ps, server, port, password, method, plugin, pluginopts, libev); nodes.emplace_back(std::move(node)); + node = nodeInfo(); index++; } } @@ -466,6 +470,7 @@ void explodeSSConf(std::string content, const std::string &custom_port, bool lib node.port = to_int(port, 1); node.proxyStr = ssConstruct(group, ps, server, port, password, method, plugin, pluginopts, libev); nodes.emplace_back(std::move(node)); + node = nodeInfo(); index++; } return; @@ -558,6 +563,7 @@ void explodeSSRConf(std::string content, const std::string &custom_port, bool ss node.proxyStr = ssrConstruct(node.group, node.remarks, base64_encode(node.remarks), server, port, protocol, method, obfs, password, obfsparam, protoparam, ssr_libev); } nodes.emplace_back(std::move(node)); + node = nodeInfo(); return; } @@ -591,6 +597,7 @@ void explodeSSRConf(std::string content, const std::string &custom_port, bool ss node.port = to_int(port, 1); node.proxyStr = ssrConstruct(group, remarks, remarks_base64, server, port, protocol, method, obfs, password, obfsparam, protoparam, ssr_libev); nodes.emplace_back(std::move(node)); + node = nodeInfo(); index++; } return; @@ -1111,6 +1118,7 @@ void explodeClash(Node yamlnode, const std::string &custom_port, std::vector