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