From 54adaffb925af78b07165cd443d0a2dee165754e Mon Sep 17 00:00:00 2001
From: 2dust <31833384+2dust@users.noreply.github.com>
Date: Wed, 17 Nov 2021 20:52:45 +0800
Subject: [PATCH] Optimize performance
---
v2rayN/v2rayN/Forms/MainForm.cs | 8 +++----
v2rayN/v2rayN/Handler/ConfigHandler.cs | 33 ++++++++++++++------------
2 files changed, 21 insertions(+), 20 deletions(-)
diff --git a/v2rayN/v2rayN/Forms/MainForm.cs b/v2rayN/v2rayN/Forms/MainForm.cs
index 7b75f1d3..d2920ae1 100644
--- a/v2rayN/v2rayN/Forms/MainForm.cs
+++ b/v2rayN/v2rayN/Forms/MainForm.cs
@@ -578,13 +578,11 @@ namespace v2rayN.Forms
{
return;
}
- for (int k = lvSelecteds.Count - 1; k >= 0; k--)
- {
- ConfigHandler.RemoveServer(ref config, lvSelecteds[k]);
- }
+
+ ConfigHandler.RemoveServer(ref config, lvSelecteds);
+
RefreshServers();
LoadV2ray();
-
}
private void menuRemoveDuplicateServer_Click(object sender, EventArgs e)
diff --git a/v2rayN/v2rayN/Handler/ConfigHandler.cs b/v2rayN/v2rayN/Handler/ConfigHandler.cs
index a447754a..0b83a515 100644
--- a/v2rayN/v2rayN/Handler/ConfigHandler.cs
+++ b/v2rayN/v2rayN/Handler/ConfigHandler.cs
@@ -236,19 +236,27 @@ namespace v2rayN.Handler
///
///
///
- public static int RemoveServer(ref Config config, int index)
+ public static int RemoveServer(ref Config config, List indexs)
{
- if (index < 0 || index > config.vmess.Count - 1)
+ var itemId = config.getItemId();
+
+ for (int k = indexs.Count - 1; k >= 0; k--)
{
- return -1;
+ var index = indexs[k];
+ if (index < 0 || index > config.vmess.Count - 1)
+ {
+ continue;
+ }
+
+ config.vmess.RemoveAt(index);
}
- //删除
- config.vmess.RemoveAt(index);
-
-
- //移除的是活动的
- if (config.index.Equals(index))
+ var index_ = config.vmess.FindIndex(it => it.getItemId() == itemId);
+ if (index_ >= 0)
+ {
+ config.index = index_;
+ }
+ else
{
if (config.vmess.Count > 0)
{
@@ -258,13 +266,8 @@ namespace v2rayN.Handler
{
config.index = -1;
}
- Global.reloadV2ray = true;
- }
- else if (index < config.index)//移除活动之前的
- {
- config.index--;
- Global.reloadV2ray = true;
}
+ Global.reloadV2ray = true;
ToJsonFile(config);