Skip to content

Commit

Permalink
perf: 合并词库时检查词条有无编码
Browse files Browse the repository at this point in the history
  • Loading branch information
nopdan committed Oct 20, 2024
1 parent 30a67ea commit 3aded7f
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/IME WL Converter Win/Forms/MergeWLForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,17 +92,17 @@ private void btnMergeWL_Click(object sender, EventArgs e)
}
}

private Dictionary<string, List<string>> ConvertTxt2Dictionary(string txt)
private static Dictionary<string, List<string>> ConvertTxt2Dictionary(string txt)
{
string[] lines = txt.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
string[] lines = txt.Split(['\r', '\n'], StringSplitOptions.RemoveEmptyEntries);
var mainDict = new Dictionary<string, List<string>>();
foreach (string line in lines)
{
string[] array = line.Split(' ');
string key = array[0];
if (!mainDict.ContainsKey(key))
{
mainDict.Add(key, new List<string>());
mainDict.Add(key, []);
}
for (int i = 1; i < array.Length; i++)
{
Expand All @@ -113,20 +113,19 @@ private Dictionary<string, List<string>> ConvertTxt2Dictionary(string txt)
return mainDict;
}

private void Merge2Dict(
private static void Merge2Dict(
Dictionary<string, List<string>> d1,
Dictionary<string, List<string>> d2
)
{
foreach (var pair in d2)
{
if (!d1.ContainsKey(pair.Key))
if (!d1.TryGetValue(pair.Key, out List<string> v))
{
d1.Add(pair.Key, pair.Value);
}
else
{
List<string> v = d1[pair.Key];
foreach (string word in pair.Value)
{
if (!v.Contains(word))
Expand All @@ -143,14 +142,17 @@ private void ShowMessage(string message)
richTextBox1.AppendText(message + "\r\n");
}

private string Dict2String(Dictionary<string, List<string>> dictionary)
private static string Dict2String(Dictionary<string, List<string>> dictionary)
{
var sb = new StringBuilder();
foreach (var pair in dictionary)
{
sb.Append(pair.Key);
sb.Append(" ");
sb.Append(string.Join(" ", pair.Value.ToArray()));
if (pair.Value != null && pair.Value.Count > 0)
{
sb.Append(' ');
sb.Append(string.Join(" ", [.. pair.Value]));
}
sb.Append("\r\n");
}
return sb.ToString();
Expand Down

0 comments on commit 3aded7f

Please sign in to comment.