Add ContainsIgnoreCase helper to reduce string alloc, cleanup

This commit is contained in:
Sinai 2021-04-30 23:43:27 +10:00
parent 74ff1d8f01
commit d76bc1f812
8 changed files with 34 additions and 21 deletions

View File

@ -17,13 +17,13 @@ namespace UnityExplorer.Core.Search
var nameFilter = ""; var nameFilter = "";
if (!string.IsNullOrEmpty(input)) if (!string.IsNullOrEmpty(input))
nameFilter = input.ToLower(); nameFilter = input;
foreach (var asm in AppDomain.CurrentDomain.GetAssemblies()) foreach (var asm in AppDomain.CurrentDomain.GetAssemblies())
{ {
foreach (var type in asm.TryGetTypes().Where(it => it.IsSealed && it.IsAbstract)) foreach (var type in asm.TryGetTypes().Where(it => it.IsSealed && it.IsAbstract))
{ {
if (!string.IsNullOrEmpty(nameFilter) && !type.FullName.ToLower().Contains(nameFilter)) if (!string.IsNullOrEmpty(nameFilter) && !type.FullName.ContainsIgnoreCase(nameFilter))
continue; continue;
list.Add(type); list.Add(type);
@ -53,7 +53,7 @@ namespace UnityExplorer.Core.Search
var nameFilter = ""; var nameFilter = "";
if (!string.IsNullOrEmpty(input)) if (!string.IsNullOrEmpty(input))
nameFilter = input.ToLower(); nameFilter = input;
var flags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static; var flags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static;
@ -64,7 +64,7 @@ namespace UnityExplorer.Core.Search
{ {
try try
{ {
if (!string.IsNullOrEmpty(nameFilter) && !type.FullName.ToLower().Contains(nameFilter)) if (!string.IsNullOrEmpty(nameFilter) && !type.FullName.ContainsIgnoreCase(nameFilter))
continue; continue;
ReflectionProvider.Instance.FindSingleton(s_instanceNames, type, flags, instances); ReflectionProvider.Instance.FindSingleton(s_instanceNames, type, flags, instances);
@ -138,7 +138,7 @@ namespace UnityExplorer.Core.Search
string nameFilter = null; string nameFilter = null;
if (!string.IsNullOrEmpty(input)) if (!string.IsNullOrEmpty(input))
nameFilter = input.ToLower(); nameFilter = input;
bool canGetGameObject = (sceneFilter != SceneFilter.Any || childFilter != ChildFilter.Any) bool canGetGameObject = (sceneFilter != SceneFilter.Any || childFilter != ChildFilter.Any)
&& (context == SearchContext.GameObject || typeof(Component).IsAssignableFrom(searchType)); && (context == SearchContext.GameObject || typeof(Component).IsAssignableFrom(searchType));
@ -152,7 +152,7 @@ namespace UnityExplorer.Core.Search
foreach (var obj in allObjects) foreach (var obj in allObjects)
{ {
// name check // name check
if (!string.IsNullOrEmpty(nameFilter) && !obj.name.ToLower().Contains(nameFilter)) if (!string.IsNullOrEmpty(nameFilter) && !obj.name.ContainsIgnoreCase(nameFilter))
continue; continue;
if (canGetGameObject) if (canGetGameObject)

View File

@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
namespace UnityExplorer
{
public static class MiscUtility
{
private static CultureInfo _enCulture = new CultureInfo("en-US");
public static bool ContainsIgnoreCase(this string _this, string s)
{
return _enCulture.CompareInfo.IndexOf(_this, s, CompareOptions.IgnoreCase) >= 0;
}
}
}

View File

@ -59,7 +59,7 @@ namespace UnityExplorer.UI.Widgets.AutoComplete
string displayName = Utility.SignatureHighlighter.ParseFullSyntax(type, true); string displayName = Utility.SignatureHighlighter.ParseFullSyntax(type, true);
string fullName = RuntimeProvider.Instance.Reflection.GetDeobfuscatedType(type).FullName; string fullName = RuntimeProvider.Instance.Reflection.GetDeobfuscatedType(type).FullName;
string filteredName = fullName.ToLower(); string filteredName = fullName;
list.Add(new CachedType list.Add(new CachedType
{ {
@ -89,7 +89,7 @@ namespace UnityExplorer.UI.Widgets.AutoComplete
timeOfLastCheck = Time.time; timeOfLastCheck = Time.time;
value = value?.ToLower() ?? ""; value = value ?? "";
if (string.IsNullOrEmpty(value)) if (string.IsNullOrEmpty(value))
{ {
@ -118,7 +118,7 @@ namespace UnityExplorer.UI.Widgets.AutoComplete
if (added.Contains(entry.FullNameValue)) if (added.Contains(entry.FullNameValue))
continue; continue;
if (entry.FullNameForFilter.Contains(value)) if (entry.FullNameForFilter.ContainsIgnoreCase(value))
AddToDict(entry); AddToDict(entry);
added.Add(entry.FullNameValue); added.Add(entry.FullNameValue);

View File

@ -25,7 +25,7 @@ namespace UnityExplorer.UI.Widgets
public string CurrentFilter public string CurrentFilter
{ {
get => currentFilter; get => currentFilter;
set => currentFilter = value?.ToLower() ?? ""; set => currentFilter = value ?? "";
} }
private string currentFilter; private string currentFilter;

View File

@ -13,8 +13,6 @@ namespace UnityExplorer.UI.Widgets
public int InstanceID { get; private set; } public int InstanceID { get; private set; }
public CachedTransform Parent { get; internal set; } public CachedTransform Parent { get; internal set; }
//public string Name { get; internal set; }
//public int ChildCount { get; internal set; }
public int Depth { get; internal set; } public int Depth { get; internal set; }
public bool Expanded => Tree.IsCellExpanded(InstanceID); public bool Expanded => Tree.IsCellExpanded(InstanceID);
@ -24,15 +22,13 @@ namespace UnityExplorer.UI.Widgets
Tree = tree; Tree = tree;
Value = transform; Value = transform;
Parent = parent; Parent = parent;
InstanceID = transform.GetInstanceID();
Update(transform, depth); Update(transform, depth);
} }
public void Update(Transform transform, int depth) public void Update(Transform transform, int depth)
{ {
Value = transform; Value = transform;
InstanceID = transform.GetInstanceID();
//Name = Value.name;
//ChildCount = Value.childCount;
Depth = depth; Depth = depth;
} }
} }

View File

@ -22,7 +22,7 @@ namespace UnityExplorer.UI.Widgets
get => currentFilter; get => currentFilter;
set set
{ {
currentFilter = value?.ToLower() ?? ""; currentFilter = value ?? "";
if (!wasFiltering && Filtering) if (!wasFiltering && Filtering)
wasFiltering = true; wasFiltering = true;
else if (wasFiltering && !Filtering) else if (wasFiltering && !Filtering)
@ -133,7 +133,7 @@ namespace UnityExplorer.UI.Widgets
private bool FilterHierarchy(Transform obj) private bool FilterHierarchy(Transform obj)
{ {
if (obj.name.ToLower().Contains(currentFilter)) if (obj.name.ContainsIgnoreCase(currentFilter))
return true; return true;
if (obj.childCount <= 0) if (obj.childCount <= 0)
@ -146,10 +146,8 @@ namespace UnityExplorer.UI.Widgets
return false; return false;
} }
public void SetCell(TransformCell iCell, int index) public void SetCell(TransformCell cell, int index)
{ {
var cell = iCell as TransformCell;
if (index < displayedObjects.Count) if (index < displayedObjects.Count)
cell.ConfigureCell(displayedObjects[index], index); cell.ConfigureCell(displayedObjects[index], index);
else else

View File

@ -219,6 +219,7 @@
<Compile Include="Core\Config\InternalConfigHandler.cs" /> <Compile Include="Core\Config\InternalConfigHandler.cs" />
<Compile Include="Core\CSharp\ScriptEvaluator.cs" /> <Compile Include="Core\CSharp\ScriptEvaluator.cs" />
<Compile Include="Core\CSharp\ScriptInteraction.cs" /> <Compile Include="Core\CSharp\ScriptInteraction.cs" />
<Compile Include="Core\Utility\MiscUtility.cs" />
<Compile Include="Inspectors_OLD\GameObjects\ChildList.cs" /> <Compile Include="Inspectors_OLD\GameObjects\ChildList.cs" />
<Compile Include="Inspectors_OLD\GameObjects\ComponentList.cs" /> <Compile Include="Inspectors_OLD\GameObjects\ComponentList.cs" />
<Compile Include="Inspectors_OLD\GameObjects\GameObjectControls.cs" /> <Compile Include="Inspectors_OLD\GameObjects\GameObjectControls.cs" />
@ -280,7 +281,7 @@
<Compile Include="Core\Search\SearchContext.cs" /> <Compile Include="Core\Search\SearchContext.cs" />
<Compile Include="Core\Search\SearchProvider.cs" /> <Compile Include="Core\Search\SearchProvider.cs" />
<Compile Include="Core\Tests\TestClass.cs" /> <Compile Include="Core\Tests\TestClass.cs" />
<Compile Include="Core\Unity\UnityHelpers.cs" /> <Compile Include="Core\Utility\UnityHelpers.cs" />
<Compile Include="ExplorerCore.cs" /> <Compile Include="ExplorerCore.cs" />
<Compile Include="Loader\BIE\BepInExConfigHandler.cs" /> <Compile Include="Loader\BIE\BepInExConfigHandler.cs" />
<Compile Include="Loader\BIE\ExplorerBepInPlugin.cs" /> <Compile Include="Loader\BIE\ExplorerBepInPlugin.cs" />