Removed some LINQ

This commit is contained in:
2026-01-24 21:47:18 +00:00
parent 434b902814
commit e905c1f7c5
2 changed files with 43 additions and 51 deletions

View File

@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Reflection; using System.Reflection;
using System.Linq; using System.Linq;
using System; using System;
using PashaBibko.Pacore.DevTools;
using UnityEngine; using UnityEngine;
namespace PashaBibko.Pacore namespace PashaBibko.Pacore
@@ -13,13 +14,15 @@ namespace PashaBibko.Pacore
public static ReadOnlyCollection<Type> GetAttributesOf<T>() public static ReadOnlyCollection<Type> GetAttributesOf<T>()
{ {
return AttributeCache.TryGetValue(typeof(T), out List<Type> classes) ? return AttributeCache.TryGetValue(typeof(T), out List<Type> classes)
classes.AsReadOnly() : ? classes.AsReadOnly()
throw new ArgumentException($"Attribute [{nameof(T)}] is not used by any classes"); : throw new ArgumentException($"Attribute [{nameof(T)}] is not used by any classes");
} }
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.AfterAssembliesLoaded)] [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.AfterAssembliesLoaded)]
private static void ScanAllAssemblies() private static void ScanAllAssemblies()
{
using (CodeProfiler.Start("Assembly scan"))
{ {
/* Fetches all the class types in all loaded assemblies */ /* Fetches all the class types in all loaded assemblies */
Type[] classes = AppDomain.CurrentDomain.GetAssemblies() // Assembly[] Type[] classes = AppDomain.CurrentDomain.GetAssemblies() // Assembly[]
@@ -48,18 +51,21 @@ namespace PashaBibko.Pacore
); // Dictionary<Type, List<Type>> ); // Dictionary<Type, List<Type>>
/* Finds which attributes are attached to what classes */ /* Finds which attributes are attached to what classes */
HashSet<Type> seen = new();
foreach (Type current in classes) foreach (Type current in classes)
{ {
/* Finds all the attributes of the current class */ /* Tracks the seen attributes */
Type[] attached = current // Type seen.Clear();
.GetCustomAttributes(inherit: true) // object[] foreach (object attr in current.GetCustomAttributes(inherit: true))
.Select(attribute => attribute.GetType()) // IEnumerable<Type> {
.Distinct().ToArray(); seen.Add(attr.GetType());
}
/* Adds the class type to each attribute in the dictionary */ /* Adds the class type to each attribute in the dictionary */
foreach (Type attribute in attached) foreach (Type type in seen)
{ {
AttributeCache[attribute].Add(current); AttributeCache[type].Add(current);
}
} }
} }
} }

View File

@@ -14,20 +14,6 @@ using UnityEngine;
private void OnTestChange() => LogTestValue(); private void OnTestChange() => LogTestValue();
private void Update()
{
using (CodeProfiler.Start("Test Snippet"))
{
SpinWait sw = new();
int count = Random.Range(1, 50);
for (int i = 0; i < count; i++)
{
sw.SpinOnce();
}
}
}
[InspectorCallable(nameof(LogSpawnableType))] [InspectorCallable(nameof(LogSpawnableType))]
public void LogSpawnableType() public void LogSpawnableType()
{ {