mirror of
https://github.com/bdunderscore/modular-avatar.git
synced 2025-04-24 13:29:01 +08:00
Eliminate caching of ImmutableArray and use ImmutableList
This commit is contained in:
parent
edab9da269
commit
ead1b69856
@ -10,6 +10,7 @@ namespace nadena.dev.modular_avatar.core.editor
|
|||||||
{
|
{
|
||||||
internal class MenuTree
|
internal class MenuTree
|
||||||
{
|
{
|
||||||
|
|
||||||
public struct ChildElement
|
public struct ChildElement
|
||||||
{
|
{
|
||||||
public string menuName;
|
public string menuName;
|
||||||
@ -19,22 +20,16 @@ namespace nadena.dev.modular_avatar.core.editor
|
|||||||
public bool isInstallerRoot;
|
public bool isInstallerRoot;
|
||||||
}
|
}
|
||||||
|
|
||||||
private class ImmutableBuilder
|
|
||||||
{
|
|
||||||
public ImmutableArray<ChildElement> immutableArray;
|
|
||||||
public ImmutableArray<ChildElement>.Builder builder;
|
|
||||||
}
|
|
||||||
|
|
||||||
private readonly HashSet<VRCExpressionsMenu> _included;
|
private readonly HashSet<VRCExpressionsMenu> _included;
|
||||||
|
|
||||||
private readonly VRCExpressionsMenu _rootMenu;
|
private readonly VRCExpressionsMenu _rootMenu;
|
||||||
private readonly Dictionary<VRCExpressionsMenu, ImmutableBuilder> _menuChildrenMap;
|
private readonly Dictionary<VRCExpressionsMenu, ImmutableList<ChildElement>> _menuChildrenMap;
|
||||||
|
|
||||||
public MenuTree(VRCAvatarDescriptor descriptor)
|
public MenuTree(VRCAvatarDescriptor descriptor)
|
||||||
{
|
{
|
||||||
_rootMenu = descriptor.expressionsMenu;
|
_rootMenu = descriptor.expressionsMenu;
|
||||||
_included = new HashSet<VRCExpressionsMenu>();
|
_included = new HashSet<VRCExpressionsMenu>();
|
||||||
_menuChildrenMap = new Dictionary<VRCExpressionsMenu, ImmutableBuilder>();
|
_menuChildrenMap = new Dictionary<VRCExpressionsMenu, ImmutableList<ChildElement>>();
|
||||||
|
|
||||||
if (_rootMenu == null)
|
if (_rootMenu == null)
|
||||||
{
|
{
|
||||||
@ -57,15 +52,10 @@ namespace nadena.dev.modular_avatar.core.editor
|
|||||||
TraverseMenu(installer);
|
TraverseMenu(installer);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ImmutableArray<ChildElement> GetChildren(VRCExpressionsMenu parent)
|
public ImmutableList<ChildElement> GetChildren(VRCExpressionsMenu parent)
|
||||||
{
|
{
|
||||||
if (parent == null) parent = _rootMenu;
|
if (parent == null) parent = _rootMenu;
|
||||||
if (!_menuChildrenMap.TryGetValue(parent, out ImmutableBuilder immutableBuilder)) return ImmutableArray<ChildElement>.Empty;
|
return !_menuChildrenMap.TryGetValue(parent, out ImmutableList<ChildElement> immutableList) ? ImmutableList<ChildElement>.Empty : immutableList;
|
||||||
if (immutableBuilder.immutableArray == ImmutableArray<ChildElement>.Empty)
|
|
||||||
{
|
|
||||||
immutableBuilder.immutableArray = immutableBuilder.builder.ToImmutable();
|
|
||||||
}
|
|
||||||
return immutableBuilder.immutableArray;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<ChildElement> GetChildInstallers(ModularAvatarMenuInstaller parentInstaller)
|
public IEnumerable<ChildElement> GetChildInstallers(ModularAvatarMenuInstaller parentInstaller)
|
||||||
@ -165,18 +155,13 @@ namespace nadena.dev.modular_avatar.core.editor
|
|||||||
{
|
{
|
||||||
if (parent == null) parent = _rootMenu;
|
if (parent == null) parent = _rootMenu;
|
||||||
childElement.parent = parent;
|
childElement.parent = parent;
|
||||||
if (!_menuChildrenMap.TryGetValue(parent, out ImmutableBuilder children))
|
if (!_menuChildrenMap.TryGetValue(parent, out ImmutableList<ChildElement> children))
|
||||||
{
|
{
|
||||||
children = new ImmutableBuilder
|
children = ImmutableList<ChildElement>.Empty;
|
||||||
{
|
|
||||||
builder = ImmutableArray.CreateBuilder<ChildElement>(),
|
|
||||||
immutableArray = ImmutableArray<ChildElement>.Empty
|
|
||||||
};
|
|
||||||
_menuChildrenMap[parent] = children;
|
_menuChildrenMap[parent] = children;
|
||||||
}
|
}
|
||||||
|
|
||||||
children.builder.Add(childElement);
|
_menuChildrenMap[parent] = children.Add(childElement);
|
||||||
children.immutableArray = ImmutableArray<ChildElement>.Empty;
|
|
||||||
if (childElement.menu == null) return;
|
if (childElement.menu == null) return;
|
||||||
if (_included.Contains(childElement.menu)) return;
|
if (_included.Contains(childElement.menu)) return;
|
||||||
_included.Add(childElement.menu);
|
_included.Add(childElement.menu);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user