perf. remove std::as_const, add const& to lambda

This commit is contained in:
lhhxxxxx
2022-08-02 17:34:37 +08:00
parent b1b938bad9
commit 102a200cd3
8 changed files with 21 additions and 22 deletions

View File

@@ -271,7 +271,7 @@ asst::AutoRecruitTask::calc_task_result_type asst::AutoRecruitTask::recruit_calc
// special tags
const std::vector<std::string> SpecialTags = { "高级资深干员", "资深干员" };
auto special_iter = std::ranges::find_first_of(SpecialTags, std::as_const(tag_names));
auto special_iter = std::ranges::find_first_of(SpecialTags, tag_names);
if (special_iter != SpecialTags.cend()) {
json::value info = basic_info();
info["what"] = "RecruitSpecialTag";
@@ -282,7 +282,7 @@ asst::AutoRecruitTask::calc_task_result_type asst::AutoRecruitTask::recruit_calc
// robot tags
const std::vector<std::string> RobotTags = { "支援机械" };
auto robot_iter = std::ranges::find_first_of(RobotTags, std::as_const(tag_names));
auto robot_iter = std::ranges::find_first_of(RobotTags, tag_names);
if (robot_iter != RobotTags.cend()) {
json::value info = basic_info();
info["what"] = "RecruitRobotTag";
@@ -410,7 +410,7 @@ asst::AutoRecruitTask::calc_task_result_type asst::AutoRecruitTask::recruit_calc
if (!is_calc_only_task()) {
// do not confirm, force skip
if (std::ranges::none_of(std::as_const(m_confirm_level), [&](const auto& i) { return i == final_combination.min_level; })) {
if (std::ranges::none_of(m_confirm_level, [&](const auto& i) { return i == final_combination.min_level; })) {
calc_task_result_type result;
result.success = true;
result.force_skip = true;
@@ -433,7 +433,7 @@ asst::AutoRecruitTask::calc_task_result_type asst::AutoRecruitTask::recruit_calc
}
// nothing to select, leave the selection empty
if (std::ranges::none_of(std::as_const(m_select_level), [&](const auto& i) { return i == final_combination.min_level; })) {
if (std::ranges::none_of(m_select_level, [&](const auto& i) { return i == final_combination.min_level; })) {
calc_task_result_type result;
result.success = true;
result.force_skip = false;

View File

@@ -500,7 +500,7 @@ bool asst::BattleImageAnalyzer::kills_analyze()
// 例子中的"0"
std::string kills_count = kills_text.substr(0, pos);
if (kills_count.empty() ||
!std::ranges::all_of(std::as_const(kills_count),
!std::ranges::all_of(kills_count,
[](char c) -> bool {return std::isdigit(c);})) {
return false;
}
@@ -511,7 +511,7 @@ bool asst::BattleImageAnalyzer::kills_analyze()
std::string total_kills = kills_text.substr(pos + 1, std::string::npos);
int cur_total_kills = 0;
if (total_kills.empty() ||
!std::ranges::all_of(std::as_const(total_kills),
!std::ranges::all_of(total_kills,
[](char c) -> bool {return std::isdigit(c);})) {
Log.warn("total kills recognition failed, set to", m_pre_total_kills);
cur_total_kills = m_pre_total_kills;
@@ -539,8 +539,8 @@ bool asst::BattleImageAnalyzer::cost_analyze()
std::string cost_str = cost_analyzer.get_result().front().text;
if (cost_str.empty() ||
!std::ranges::all_of(std::as_const(cost_str),
[](char c) -> bool {return std::isdigit(c);})) {
!std::ranges::all_of(cost_str,
[](const char& c) -> bool {return std::isdigit(c);})) {
return false;
}
m_cost = std::stoi(cost_str);

View File

@@ -281,8 +281,8 @@ int asst::DepotImageAnalyzer::match_quantity(const Rect& roi)
//}
if (digit_str.empty() ||
!std::ranges::all_of(std::as_const(digit_str),
[](char c) -> bool {return std::isdigit(c) || c == '.';})) {
!std::ranges::all_of(digit_str,
[](const char& c) -> bool {return std::isdigit(c) || c == '.';})) {
return 0;
}

View File

@@ -206,7 +206,7 @@ size_t asst::InfrastProductionTask::opers_detect()
//--cur_available_num;
continue;
}
auto find_iter = std::ranges::find_if(std::as_const(m_all_available_opers),
auto find_iter = std::ranges::find_if(m_all_available_opers,
[&](const infrast::Oper& oper) -> bool {
if (oper.skills != cur_oper.skills) {
return false;
@@ -328,7 +328,7 @@ bool asst::InfrastProductionTask::optimal_calc()
// necessary里的技能一个都不能少
// TODO necessary暂时没做hash校验。因为没有需要比hash的necessary干员
for (const infrast::SkillsComb& nec_skills : group.necessary) {
auto find_iter = std::ranges::find_if(std::as_const(cur_available_opers),
auto find_iter = std::ranges::find_if(cur_available_opers,
[&](const infrast::SkillsComb& arg) -> bool {
return arg == nec_skills;
});
@@ -500,7 +500,7 @@ bool asst::InfrastProductionTask::opers_choose()
Log.trace("after mood filter, opers size:", cur_all_opers.size());
for (auto opt_iter = m_optimal_combs.begin(); opt_iter != m_optimal_combs.end();) {
Log.trace("to find", opt_iter->skills.begin()->names.front());
auto find_iter = std::ranges::find_if(std::as_const(cur_all_opers),
auto find_iter = std::ranges::find_if(cur_all_opers,
[&](const infrast::Oper& lhs) -> bool {
if (lhs.skills != opt_iter->skills) {
return false;
@@ -540,7 +540,7 @@ bool asst::InfrastProductionTask::opers_choose()
m_ctrler->click(find_iter->rect);
}
{
auto avlb_iter = std::ranges::find_if(std::as_const(m_all_available_opers),
auto avlb_iter = std::ranges::find_if(m_all_available_opers,
[&](const infrast::Oper& lhs) -> bool {
int dist = HashImageAnalyzer::hamming(lhs.face_hash, find_iter->face_hash);
Log.debug("opers_choose | face hash dist", dist);

View File

@@ -27,7 +27,7 @@ bool asst::OcrImageAnalyzer::analyze()
if (!m_required.empty()) {
if (m_full_match) {
TextRectProc required_match = [&](TextRect& tr) -> bool {
return std::ranges::find(std::as_const(m_required), tr.text) != m_required.cend();
return std::ranges::find(m_required, tr.text) != m_required.cend();
};
preds_vec.emplace_back(required_match);
}
@@ -40,7 +40,7 @@ bool asst::OcrImageAnalyzer::analyze()
tr.text = str;
return true;
};
return std::ranges::find_if(std::as_const(m_required), is_sub) != m_required.cend();
return std::ranges::find_if(m_required, is_sub) != m_required.cend();
};
preds_vec.emplace_back(required_search);
}

View File

@@ -78,10 +78,10 @@ namespace asst
RecruitCombs result;
std::ranges::set_union(std::as_const(lhs.tags), std::as_const(rhs.tags),
std::ranges::set_union(lhs.tags, rhs.tags,
std::back_inserter(result.tags));
std::ranges::set_intersection(std::as_const(lhs.opers), std::as_const(rhs.opers),
std::ranges::set_intersection(lhs.opers, rhs.opers,
std::back_inserter(result.opers));
result.update_attributes();

View File

@@ -147,8 +147,7 @@ bool asst::RoguelikeShoppingTaskPlugin::_run()
}
if (!goods.chars.empty()) {
auto iter = std::ranges::find_first_of(std::as_const(chars_list), goods.chars);
if (iter == chars_list.cend()) {
if (std::ranges::find_first_of(chars_list, goods.chars) == chars_list.cend()) {
Log.trace("Ready to buy", goods.name,
", but there is no such character, skip");
continue;

View File

@@ -559,8 +559,8 @@ int asst::StageDropsImageAnalyzer::match_quantity(const Rect& roi)
//}
if (digit_str.empty() ||
!std::ranges::all_of(std::as_const(digit_str),
[](char c) -> bool {return std::isdigit(c) || c == '.';})) {
!std::ranges::all_of(digit_str,
[](const char& c) -> bool {return std::isdigit(c) || c == '.';})) {
return 0;
}