Skip to content

Commit 89f4fc9

Browse files
committed
update(entity/manager): useless try-catch
1 parent 67d4168 commit 89f4fc9

1 file changed

Lines changed: 8 additions & 16 deletions

File tree

managed/src/SwiftlyS2.Core/Modules/EntitySystem/EntityManager.cs

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -53,21 +53,18 @@ public static CEntityInstance OnEntityCreated( nint entityPtr )
5353

5454
public static CEntityInstance? GetEntityByAddress( nint address )
5555
{
56+
if (address == 0) return null;
57+
5658
lock (_lock)
5759
{
58-
try
59-
{
60-
return !_PtrToIndex.TryGetValue(address, out var value) ? null : _Entities[value];
61-
}
62-
catch
63-
{
64-
return null;
65-
}
60+
return !_PtrToIndex.TryGetValue(address, out var value) ? null : _Entities[value];
6661
}
6762
}
6863

6964
public static void OnEntityDeleted( nint entityPtr )
7065
{
66+
if (entityPtr == 0) return;
67+
7168
lock (_lock)
7269
{
7370
try
@@ -103,16 +100,11 @@ public static IEnumerable<CEntityInstance> GetAllEntities()
103100

104101
public static bool IsAddressValid( nint address )
105102
{
103+
if (address == 0) return false;
104+
106105
lock (_lock)
107106
{
108-
try
109-
{
110-
return _PtrToIndex.ContainsKey(address);
111-
}
112-
catch
113-
{
114-
return false;
115-
}
107+
return _PtrToIndex.ContainsKey(address);
116108
}
117109
}
118110

0 commit comments

Comments
 (0)