Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions MaiChartManager/Services/MaidataImportService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,8 @@ public ImportChartResult ImportMaidata(
foreach (var (key, value) in kvps)
{
maiData[key] = value;
if (key.StartsWith("inote") || key.StartsWith("lv") || key.StartsWith("first") ||
key.StartsWith("wholebpm")) maiData[key] = maiData[key].Trim();
Comment on lines 276 to +278
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

这里的实现虽然能正常工作,但会存在对字典的重复写入问题。当 if 条件满足时,会先执行 maiData[key] = value;,然后再执行 maiData[key] = maiData[key].Trim();,对同一个键写入了两次。

为了避免这种情况,我们可以重构一下,根据条件只写入一次。这样代码会更高效和清晰。

            if (key.StartsWith("inote") || key.StartsWith("lv") || key.StartsWith("first") ||
                key.StartsWith("wholebpm"))
            {
                maiData[key] = value.Trim();
            }
            else
            {
                maiData[key] = value;
            }

}

var allCharts = new Dictionary<int, AllChartsEntry>();
Expand Down