Skip to content

Commit

Permalink
Some performance improvements.
Browse files Browse the repository at this point in the history
  • Loading branch information
Lars Matthäus committed Aug 2, 2024
1 parent e741cd5 commit a5bba55
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
5 changes: 3 additions & 2 deletions src/Arch.SourceGen/Fundamentals/Get.cs
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,9 @@ public static StringBuilder AppendWorldGet(this StringBuilder sb, int amount)
[Pure]
public Components<{{generics}}> Get<{{generics}}>(Entity entity)
{
var slot = EntityInfo.GetSlot(entity.Id);
var archetype = EntityInfo.GetArchetype(entity.Id);
var entitySlot = EntityInfo.GetEntitySlot(entity.Id);
var slot = entitySlot.Slot;
var archetype = entitySlot.Archetype;
return archetype.Get<{{generics}}>(ref slot);
}
""";
Expand Down
5 changes: 3 additions & 2 deletions src/Arch.SourceGen/Fundamentals/Set.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,9 @@ public static StringBuilder AppendWorldSet(this StringBuilder sb, int amount)
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Set<{{generics}}>(Entity entity, {{parameters}})
{
var slot = EntityInfo.GetSlot(entity.Id);
var archetype = EntityInfo.GetArchetype(entity.Id);
var entitySlot = EntityInfo.GetEntitySlot(entity.Id);
var slot = entitySlot.Slot;
var archetype = entitySlot.Archetype;
archetype.Set<{{generics}}>(ref slot, {{insertParams}});
{{events}}
}
Expand Down
15 changes: 9 additions & 6 deletions src/Arch/Core/World.cs
Original file line number Diff line number Diff line change
Expand Up @@ -955,8 +955,9 @@ public partial class World
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Set<T>(Entity entity, in T? component = default)
{
var slot = EntityInfo.GetSlot(entity.Id);
var archetype = EntityInfo.GetArchetype(entity.Id);
var entitySlot = EntityInfo.GetEntitySlot(entity.Id);
var slot = entitySlot.Slot;
var archetype = entitySlot.Archetype;
archetype.Set(ref slot, in component);
OnComponentSet<T>(entity);
}
Expand Down Expand Up @@ -1005,8 +1006,9 @@ public bool TryGet<T>(Entity entity, out T? component)
{
component = default;

var slot = EntityInfo.GetSlot(entity.Id);
var archetype = EntityInfo.GetArchetype(entity.Id);
var entitySlot = EntityInfo.GetEntitySlot(entity.Id);
var slot = entitySlot.Slot;
var archetype = entitySlot.Archetype;

if (!archetype.Has<T>())
{
Expand All @@ -1028,8 +1030,9 @@ public bool TryGet<T>(Entity entity, out T? component)
[Pure]
public ref T TryGetRef<T>(Entity entity, out bool exists)
{
var slot = EntityInfo.GetSlot(entity.Id);
var archetype = EntityInfo.GetArchetype(entity.Id);
var entitySlot = EntityInfo.GetEntitySlot(entity.Id);
var slot = entitySlot.Slot;
var archetype = entitySlot.Archetype;

if (!(exists = archetype.Has<T>()))
{
Expand Down

0 comments on commit a5bba55

Please sign in to comment.