Skip to content

Commit 932265f

Browse files
committed
refactor(Settings): rename cache variable for clarity and optimize page build logic
- Renamed `SortedPagesCache` to `_sortedPagesCache` for improved clarity and consistency in naming conventions. - Updated references throughout the code to reflect the new variable name, ensuring proper cache invalidation during settings changes. - Simplified the page build logic in `RitsuModSettingsSubmenu` to enhance performance and maintainability by consolidating yield conditions.
1 parent ebacda7 commit 932265f

2 files changed

Lines changed: 12 additions & 14 deletions

File tree

Settings/ModSettings/Core/ModSettingsRegistry.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public static class ModSettingsRegistry
3838
/// <see cref="InvalidateOrderingCache" />)。重建开销很大(多键排序 + 逐页本地化),而设置 UI 每次刷新
3939
/// 都会多次调用 <see cref="GetPages" />,因此在真正发生变化前复用该快照。
4040
/// </summary>
41-
private static IReadOnlyList<ModSettingsPage>? SortedPagesCache;
41+
private static IReadOnlyList<ModSettingsPage>? _sortedPagesCache;
4242

4343
/// <summary>
4444
/// True after at least one page has been registered.
@@ -66,7 +66,7 @@ public static void Register(ModSettingsPage page)
6666
lock (SyncRoot)
6767
{
6868
PagesById[CreateCompositeId(page.ModId, page.Id)] = page;
69-
SortedPagesCache = null;
69+
_sortedPagesCache = null;
7070
}
7171
}
7272

@@ -81,7 +81,7 @@ public static void InvalidateOrderingCache()
8181
{
8282
lock (SyncRoot)
8383
{
84-
SortedPagesCache = null;
84+
_sortedPagesCache = null;
8585
}
8686
}
8787

@@ -97,7 +97,7 @@ public static void RegisterModDisplayName(string modId, ModSettingsText displayN
9797
lock (SyncRoot)
9898
{
9999
ModDisplayNames[modId] = displayName;
100-
SortedPagesCache = null;
100+
_sortedPagesCache = null;
101101
}
102102
}
103103

@@ -128,7 +128,7 @@ public static void RegisterModSidebarOrder(string modId, int order)
128128
lock (SyncRoot)
129129
{
130130
ModSidebarOrders[modId] = order;
131-
SortedPagesCache = null;
131+
_sortedPagesCache = null;
132132
}
133133
}
134134

@@ -146,7 +146,7 @@ public static void RegisterPageSortOrder(string modId, string pageId, int sortOr
146146
lock (SyncRoot)
147147
{
148148
PageSortOverrides[CreateCompositeId(modId, pageId)] = sortOrder;
149-
SortedPagesCache = null;
149+
_sortedPagesCache = null;
150150
}
151151
}
152152

@@ -176,7 +176,7 @@ public static bool TryRegisterPageSortOrderAfter(string modId, string pageId, st
176176
var baseOrder =
177177
PageSortOverrides.GetValueOrDefault(CreateCompositeId(modId, afterPageId), after.SortOrder);
178178
PageSortOverrides[CreateCompositeId(modId, pageId)] = baseOrder + gap;
179-
SortedPagesCache = null;
179+
_sortedPagesCache = null;
180180
return true;
181181
}
182182
}
@@ -207,7 +207,7 @@ public static bool TryRegisterPageSortOrderBefore(string modId, string pageId, s
207207
var baseOrder = PageSortOverrides.GetValueOrDefault(CreateCompositeId(modId, beforePageId),
208208
before.SortOrder);
209209
PageSortOverrides[CreateCompositeId(modId, pageId)] = baseOrder - gap;
210-
SortedPagesCache = null;
210+
_sortedPagesCache = null;
211211
return true;
212212
}
213213
}
@@ -278,7 +278,7 @@ public static IReadOnlyList<ModSettingsPage> GetPages()
278278
{
279279
lock (SyncRoot)
280280
{
281-
return SortedPagesCache ??= PagesById.Values
281+
return _sortedPagesCache ??= PagesById.Values
282282
.OrderBy(page => ModSidebarOrders.GetValueOrDefault(page.ModId, 0))
283283
.ThenBy(page => ModSettingsLocalization.ResolveModNameFallback(page.ModId, page.ModId),
284284
StringComparer.OrdinalIgnoreCase)

Settings/ModSettingsUi/Core/RitsuModSettingsSubmenu.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1956,11 +1956,9 @@ private async Task BuildPageAsync(ModSettingsPage page, PageContentCache cache)
19561956
return;
19571957

19581958
nextContent.AddChild(item.Control);
1959-
if (item.YieldAfter && Time.GetTicksMsec() - lastYieldMsec >= PageBuildFrameBudgetMsec)
1960-
{
1961-
await this.AwaitRitsuProcessFrame(ct);
1962-
lastYieldMsec = Time.GetTicksMsec();
1963-
}
1959+
if (!item.YieldAfter || Time.GetTicksMsec() - lastYieldMsec < PageBuildFrameBudgetMsec) continue;
1960+
await this.AwaitRitsuProcessFrame(ct);
1961+
lastYieldMsec = Time.GetTicksMsec();
19641962
}
19651963

19661964
if (buildVersion != cache.BuildVersion || !IsInstanceValid(cache.Root))

0 commit comments

Comments
 (0)