diff --git a/src/ini_reader.h b/src/ini_reader.h index 703b3b2..ab414dd 100644 --- a/src/ini_reader.h +++ b/src/ini_reader.h @@ -265,7 +265,7 @@ public: read_sections.push_back(curSection); //add to read sections list ini_content.emplace(curSection, itemGroup); //insert previous section to content map if(std::count(section_order.cbegin(), section_order.cend(), curSection) == 0) - section_order.emplace_back(curSection); + section_order.emplace_back(std::move(curSection)); } eraseElements(itemGroup); //reset section storage diff --git a/src/interfaces.cpp b/src/interfaces.cpp index 0fae787..1d1d8fc 100644 --- a/src/interfaces.cpp +++ b/src/interfaces.cpp @@ -358,7 +358,7 @@ int importItems(string_array &target, bool scope_limit = true) strLine.erase(--lineSize); if(!lineSize || strLine[0] == ';' || strLine[0] == '#' || (lineSize >= 2 && strLine[0] == '/' && strLine[1] == '/')) //empty lines and comments are ignored continue; - result.emplace_back(strLine); + result.emplace_back(std::move(strLine)); itemCount++; } ss.clear(); @@ -394,7 +394,7 @@ void readRegexMatch(YAML::Node node, const std::string &delimiter, string_array strLine = match + delimiter + rep; else continue; - dest.emplace_back(strLine); + dest.emplace_back(std::move(strLine)); } importItems(dest, scope_limit); } @@ -426,7 +426,7 @@ void readEmoji(YAML::Node node, string_array &dest, bool scope_limit = true) strLine = match + "," + rep; else continue; - dest.emplace_back(strLine); + dest.emplace_back(std::move(strLine)); } importItems(dest, scope_limit); } @@ -451,7 +451,7 @@ void readGroup(YAML::Node node, string_array &dest, bool scope_limit = true) std::string url = "http://www.gstatic.com/generate_204", interval = "300", tolerance, timeout; object["name"] >>= name; object["type"] >>= type; - tempArray.emplace_back(name); + tempArray.emplace_back(std::move(name)); tempArray.emplace_back(type); object["url"] >>= url; object["interval"] >>= interval; @@ -472,7 +472,7 @@ void readGroup(YAML::Node node, string_array &dest, bool scope_limit = true) default: if(tempArray.size() < 3) continue; - tempArray.emplace_back(url); + tempArray.emplace_back(std::move(url)); tempArray.emplace_back(interval + "," + timeout + "," + tolerance); } @@ -480,7 +480,7 @@ void readGroup(YAML::Node node, string_array &dest, bool scope_limit = true) { return std::move(a) + "`" + std::move(b); }); - dest.emplace_back(strLine); + dest.emplace_back(std::move(strLine)); } importItems(dest, scope_limit); } @@ -508,7 +508,7 @@ void readRuleset(YAML::Node node, string_array &dest, bool scope_limit = true) strLine = group + ",[]" + name; else continue; - dest.emplace_back(strLine); + dest.emplace_back(std::move(strLine)); } importItems(dest, scope_limit); } @@ -540,7 +540,7 @@ void refreshRulesets(string_array &ruleset_list, std::vector &r writeLog(0, "Adding rule '" + rule_url.substr(2) + "," + rule_group + "'.", LOG_LEVEL_INFO); //std::cerr<<"Adding rule '"< &r */ rc = {rule_group, rule_url, rule_url_typed, type, fetchFileAsync(rule_url, proxy, cache_ruleset, async_fetch_ruleset)}; } - rca.emplace_back(rc); + rca.emplace_back(std::move(rc)); /* if(rc.rule_content.get().size()) rca.emplace_back(rc); @@ -1555,12 +1555,14 @@ std::string subconverter(RESPONSE_CALLBACK_ARGS) return "No nodes were found!"; } prepend_insert.define(prepend_insert_url); - for(nodeInfo &x : insert_nodes) + if(prepend_insert) { - if(prepend_insert) - nodes.emplace(nodes.begin(), x); - else - nodes.emplace_back(x); + std::move(nodes.begin(), nodes.end(), std::back_inserter(insert_nodes)); + nodes.swap(insert_nodes); + } + else + { + std::move(insert_nodes.begin(), insert_nodes.end(), std::back_inserter(nodes)); } //run filter script if(filter_script.size()) @@ -2335,7 +2337,7 @@ int simpleGenerator() { x = trim(x); if(std::find(sections.cbegin(), sections.cend(), x) != sections.cend()) - new_targets.emplace_back(x); + new_targets.emplace_back(std::move(x)); else { //std::cerr<<"Artifact \""< &source, std::vector &dest) { - for(auto &x : source) - { - dest.emplace_back(x); - } + std::move(source.begin(), source.end(), std::back_inserter(dest)); } int addNodes(std::string link, std::vector &allNodes, int groupID, std::string proxy, string_array &exclude_remarks, string_array &include_remarks, string_array &stream_rules, string_array &time_rules, std::string &subInfo, bool authorized, string_map &request_headers) @@ -69,8 +66,9 @@ int addNodes(std::string link, std::vector &allNodes, int groupID, std if(link == "nullnode") { + node.groupID = 0; writeLog(0, "Adding node placeholder..."); - allNodes.emplace_back(nodeInfo{-1, -1, 0}); + allNodes.emplace_back(std::move(node)); return 0; } @@ -175,7 +173,7 @@ int addNodes(std::string link, std::vector &allNodes, int groupID, std node.groupID = groupID; if(custom_group.size()) node.group = custom_group; - allNodes.emplace_back(node); + allNodes.emplace_back(std::move(node)); } return 0; } diff --git a/src/speedtestutil.cpp b/src/speedtestutil.cpp index 1486b79..4a7e925 100644 --- a/src/speedtestutil.cpp +++ b/src/speedtestutil.cpp @@ -173,7 +173,7 @@ void explodeVmessConf(std::string content, const std::string &custom_port, bool node.server = add; 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.push_back(node); + nodes.emplace_back(std::move(node)); } return; } @@ -248,7 +248,7 @@ void explodeVmessConf(std::string content, const std::string &custom_port, bool node.id = index; node.server = add; node.port = to_int(port, 1); - nodes.push_back(node); + nodes.emplace_back(std::move(node)); } return; } @@ -379,7 +379,7 @@ void explodeSSD(std::string link, bool libev, const std::string &custom_port, st node.port = to_int(port, 1); node.proxyStr = ssConstruct(group, remarks, server, port, password, method, plugin, pluginopts, libev); node.id = index; - nodes.push_back(node); + nodes.emplace_back(std::move(node)); index++; } return; @@ -422,7 +422,7 @@ void explodeSSAndroid(std::string ss, bool libev, const std::string &custom_port node.server = server; node.port = to_int(port, 1); node.proxyStr = ssConstruct(group, ps, server, port, password, method, plugin, pluginopts, libev); - nodes.push_back(node); + nodes.emplace_back(std::move(node)); index++; } } @@ -464,7 +464,7 @@ void explodeSSConf(std::string content, const std::string &custom_port, bool lib node.server = server; node.port = to_int(port, 1); node.proxyStr = ssConstruct(group, ps, server, port, password, method, plugin, pluginopts, libev); - nodes.push_back(node); + nodes.emplace_back(std::move(node)); index++; } return; @@ -556,7 +556,7 @@ void explodeSSRConf(std::string content, const std::string &custom_port, bool ss node.group = SSR_DEFAULT_GROUP; node.proxyStr = ssrConstruct(node.group, node.remarks, base64_encode(node.remarks), server, port, protocol, method, obfs, password, obfsparam, protoparam, ssr_libev); } - nodes.push_back(node); + nodes.emplace_back(std::move(node)); return; } @@ -589,7 +589,7 @@ void explodeSSRConf(std::string content, const std::string &custom_port, bool ss node.server = server; node.port = to_int(port, 1); node.proxyStr = ssrConstruct(group, remarks, remarks_base64, server, port, protocol, method, obfs, password, obfsparam, protoparam, ssr_libev); - nodes.push_back(node); + nodes.emplace_back(std::move(node)); index++; } return; @@ -1109,7 +1109,7 @@ void explodeClash(Node yamlnode, const std::string &custom_port, std::vector &nodes, string_array &exclude_remarks, st std::unique_ptr pattern(pcre2_compile(reinterpret_cast(exclude_remarks[i].c_str()), PCRE2_ZERO_TERMINATED | PCRE2_MULTILINE, 0, &errornumber, &erroroffset, NULL), &pcre2_code_free); if(!pattern) return; - exclude_patterns.push_back(std::move(pattern)); + exclude_patterns.emplace_back(std::move(pattern)); pcre2_jit_compile(exclude_patterns[i].get(), 0); std::unique_ptr match_data(pcre2_match_data_create_from_pattern(exclude_patterns[i].get(), NULL), &pcre2_match_data_free); - exclude_match_data.push_back(std::move(match_data)); + exclude_match_data.emplace_back(std::move(match_data)); } for(i = 0; i < include_remarks.size(); i++) { std::unique_ptr pattern(pcre2_compile(reinterpret_cast(include_remarks[i].c_str()), PCRE2_ZERO_TERMINATED | PCRE2_MULTILINE, 0, &errornumber, &erroroffset, NULL), &pcre2_code_free); if(!pattern) return; - include_patterns.push_back(std::move(pattern)); + include_patterns.emplace_back(std::move(pattern)); pcre2_jit_compile(include_patterns[i].get(), 0); std::unique_ptr match_data(pcre2_match_data_create_from_pattern(include_patterns[i].get(), NULL), &pcre2_match_data_free); - include_match_data.push_back(std::move(match_data)); + include_match_data.emplace_back(std::move(match_data)); } writeLog(LOG_TYPE_INFO, "Filter started."); while(iter != nodes.end()) diff --git a/src/subexport.cpp b/src/subexport.cpp index d014958..3912fcd 100644 --- a/src/subexport.cpp +++ b/src/subexport.cpp @@ -642,7 +642,7 @@ void rulesetToClash(YAML::Node &base_rule, std::vector &ruleset strLine += "," + rule_group; if(count_least(strLine, ',', 3)) strLine = regReplace(strLine, "^(.*?,.*?)(,.*)(,.*)$", "$1$3$2"); - allRules.emplace_back(strLine); + allRules.emplace_back(std::move(strLine)); total_rules++; continue; } @@ -683,7 +683,7 @@ void rulesetToClash(YAML::Node &base_rule, std::vector &ruleset strLine += "," + rule_group; if(count_least(strLine, ',', 3)) strLine = regReplace(strLine, "^(.*?,.*?)(,.*)(,.*)$", "$1$3$2"); - allRules.emplace_back(strLine); + allRules.emplace_back(std::move(strLine)); //Rules.push_back(strLine); } } @@ -828,7 +828,7 @@ void rulesetToSurge(INIReader &base_rule, std::vector &ruleset_ strLine = regReplace(strLine, rule_match_regex, "$1$3$2"); } strLine = replace_all_distinct(strLine, ",,", ","); - allRules.emplace_back(strLine); + allRules.emplace_back(std::move(strLine)); total_rules++; continue; } @@ -845,7 +845,7 @@ void rulesetToSurge(INIReader &base_rule, std::vector &ruleset_ if(surge_ver > 2 && remote_path_prefix.size()) { strLine = "RULE-SET," + remote_path_prefix + "/getruleset?type=1&url=" + urlsafe_base64_encode(rule_path_typed) + "," + rule_group; - allRules.emplace_back(strLine); + allRules.emplace_back(std::move(strLine)); continue; } else if(surge_ver == -1 && remote_path_prefix.size()) @@ -876,7 +876,7 @@ void rulesetToSurge(INIReader &base_rule, std::vector &ruleset_ else strLine = "RULE-SET," + rule_path + "," + rule_group; - allRules.emplace_back(strLine); + allRules.emplace_back(std::move(strLine)); continue; } else if(surge_ver == -1 && remote_path_prefix.size()) @@ -961,7 +961,7 @@ void rulesetToSurge(INIReader &base_rule, std::vector &ruleset_ if(count_least(strLine, ',', 3)) strLine = regReplace(strLine, rule_match_regex, "$1$3$2"); } - allRules.emplace_back(strLine); + allRules.emplace_back(std::move(strLine)); total_rules++; } } @@ -1306,7 +1306,7 @@ void netchToClash(std::vector &nodes, YAML::Node &yamlnode, const stri singleproxy["udp"] = true; singleproxy.SetStyle(YAML::EmitterStyle::Flow); proxies.push_back(singleproxy); - remarks_list.emplace_back(remark); + remarks_list.emplace_back(std::move(remark)); nodelist.emplace_back(x); } @@ -1557,12 +1557,12 @@ std::string netchToSurge(std::vector &nodes, const std::string &base_c if(obfsparam.size()) { args.emplace_back("-g"); - args.emplace_back(obfsparam); + args.emplace_back(std::move(obfsparam)); } if(protoparam.size()) { args.emplace_back("-G"); - args.emplace_back(protoparam); + args.emplace_back(std::move(protoparam)); } proxy += std::accumulate(std::next(args.begin()), args.end(), args[0], [](std::string a, std::string b) { @@ -1617,7 +1617,6 @@ std::string netchToSurge(std::vector &nodes, const std::string &base_c if(udp) proxy += ", udp-relay=true"; - remarks_list.emplace_back(remark); if(ext.nodelist) output_nodelist += remark + " = " + proxy + "\n"; else @@ -1625,6 +1624,7 @@ std::string netchToSurge(std::vector &nodes, const std::string &base_c ini.Set("{NONAME}", remark + " = " + proxy); nodelist.emplace_back(x); } + remarks_list.emplace_back(std::move(remark)); } if(ext.nodelist) @@ -2054,7 +2054,7 @@ void netchToQuan(std::vector &nodes, INIReader &ini, std::vector &nodes, INIReader &ini, std::vector &nodes, INIReader &ini, std::vector &nodes, const std::string &base_co { ini.Set("{NONAME}", remark + " = " + proxy); nodelist.emplace_back(x); - remarks_list.emplace_back(remark); + remarks_list.emplace_back(std::move(remark)); } } diff --git a/src/templates.cpp b/src/templates.cpp index 3d94f1f..3103fc0 100644 --- a/src/templates.cpp +++ b/src/templates.cpp @@ -263,7 +263,7 @@ int renderClashScript(YAML::Node &base_rule, std::vector &rules strLine += "," + rule_group; if(count_least(strLine, ',', 3)) strLine = regReplace(strLine, "^(.*?,.*?)(,.*)(,.*)$", "$1$3$2"); - rules.emplace_back(strLine); + rules.emplace_back(std::move(strLine)); continue; } else @@ -290,7 +290,7 @@ int renderClashScript(YAML::Node &base_rule, std::vector &rules rules.emplace_back("RULE-SET," + rule_group + "_" + rule_name + "_classical," + rule_group); break; } - groups.emplace_back(rule_name); + groups.emplace_back(std::move(rule_name)); continue; } if(remote_path_prefix.size()) @@ -302,9 +302,9 @@ int renderClashScript(YAML::Node &base_rule, std::vector &rules urls[rule_name] = rule_path_typed; if(clash_classical_ruleset) { - groups.emplace_back(rule_name); if(!script) rules.emplace_back("RULE-SET," + rule_group + "_" + rule_name + "_classical," + rule_group); + groups.emplace_back(std::move(rule_name)); continue; } } @@ -350,12 +350,12 @@ int renderClashScript(YAML::Node &base_rule, std::vector &rules strLine += "," + rule_group; if(count_least(strLine, ',', 3)) strLine = regReplace(strLine, "^(.*?,.*?)(,.*)(,.*)$", "$1$3$2"); - rules.emplace_back(strLine); + rules.emplace_back(std::move(strLine)); } } - else if(startsWith(strLine, "DOMAIN,") || startsWith(strLine, "DOMAIN-SUFFIX,")) + else if(!has_domain[rule_name] && (startsWith(strLine, "DOMAIN,") || startsWith(strLine, "DOMAIN-SUFFIX,"))) has_domain[rule_name] = true; - else if(startsWith(strLine, "IP-CIDR,") || startsWith(strLine, "IP-CIDR6,")) + else if(!has_ipcidr[rule_name] && (startsWith(strLine, "IP-CIDR,") || startsWith(strLine, "IP-CIDR6,"))) has_ipcidr[rule_name] = true; } if(has_domain[rule_name] && !script) @@ -363,7 +363,7 @@ int renderClashScript(YAML::Node &base_rule, std::vector &rules if(has_ipcidr[rule_name] && !script) rules.emplace_back("RULE-SET," + rule_group + "_" + rule_name + "_ipcidr," + rule_group); if(std::find(groups.begin(), groups.end(), rule_name) == groups.end()) - groups.emplace_back(rule_name); + groups.emplace_back(std::move(rule_name)); } } for(std::string &x : groups) diff --git a/src/webserver.cpp b/src/webserver.cpp index ad6f864..9b19eba 100644 --- a/src/webserver.cpp +++ b/src/webserver.cpp @@ -247,14 +247,14 @@ end: working_thread--; } -void append_response(std::string type, std::string request, std::string content_type, response_callback response) +void append_response(const std::string &type, const std::string &request, const std::string &content_type, response_callback response) { responseRoute rr; rr.method = type; rr.path = request; rr.content_type = content_type; rr.rc = response; - responses.push_back(rr); + responses.push_back(std::move(rr)); } void stop_web_server() diff --git a/src/webserver_libevent.cpp b/src/webserver_libevent.cpp index c4eca96..c3ec434 100644 --- a/src/webserver_libevent.cpp +++ b/src/webserver_libevent.cpp @@ -322,7 +322,7 @@ void append_response(const std::string &method, const std::string &uri, const st rr.path = uri; rr.content_type = content_type; rr.rc = response; - responses.emplace_back(rr); + responses.emplace_back(std::move(rr)); } void append_redirect(const std::string &uri, const std::string &target)