Skip to content

Commit 951355a

Browse files
author
Sam Byass
committed
Lib: Minor performance improvements, add offset to fieldreflectiondata
1 parent 0fc9f71 commit 951355a

File tree

4 files changed

+29
-5
lines changed

4 files changed

+29
-5
lines changed

Cpp2IL/ConsoleLogger.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ internal static void Write(string level, string source, string message, Color co
3939
if (!LastNoNewline)
4040
WritePrelude(level, source, color);
4141

42-
LastNoNewline = !message.EndsWith("\n");
42+
LastNoNewline = message[^1] != '\n';
4343

4444
if (!DisableColor)
4545
message = message.Pastel(color);
@@ -74,6 +74,11 @@ public static void CheckColorSupport()
7474
DisableColor = true; //Just manually set this, even though Pastel respects the environment variable
7575
Logger.WarnNewline("NO_COLOR set, disabling ANSI color codes as you requested.");
7676
}
77+
else
78+
{
79+
//Ensure we run the cctor for Pastel now.
80+
ConsoleExtensions.Enable();
81+
}
7782
}
7883
}
7984
}

LibCpp2IL/BinarySearcher.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,11 @@ private static int FindSequence(byte[] haystack, byte[] needle, int requiredAlig
2828
{
2929
//Convert needle to a span now, rather than in the loop (implicitly as call to SequenceEqual)
3030
var needleSpan = new ReadOnlySpan<byte>(needle);
31+
var haystackSpan = haystack.AsSpan();
32+
var firstByte = needleSpan[0];
3133

3234
//Find the first occurrence of the first byte of the needle
33-
var nextMatchIdx = Array.IndexOf(haystack, needle[0], startOffset);
35+
var nextMatchIdx = Array.IndexOf(haystack, firstByte, startOffset);
3436

3537
var needleLength = needleSpan.Length;
3638
var endIdx = haystack.Length - needleLength;
@@ -42,12 +44,12 @@ private static int FindSequence(byte[] haystack, byte[] needle, int requiredAlig
4244
if (!checkAlignment || nextMatchIdx % requiredAlignment == 0)
4345
{
4446
//Take a slice of the array at this position and the length of the needle, and compare
45-
if (haystack.AsSpan(nextMatchIdx, needleLength).SequenceEqual(needleSpan))
47+
if (haystackSpan.Slice(nextMatchIdx, needleLength).SequenceEqual(needleSpan))
4648
return nextMatchIdx;
4749
}
4850

4951
//Find the next occurrence of the first byte of the needle
50-
nextMatchIdx = Array.IndexOf(haystack, needle[0], nextMatchIdx + 1);
52+
nextMatchIdx = Array.IndexOf(haystack, firstByte, nextMatchIdx + 1);
5153
}
5254

5355
//No match found

LibCpp2IL/Metadata/Il2CppTypeDefinition.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,24 @@ public Il2CppFieldReflectionData[]? FieldInfos
252252
var attributes = FieldAttributes;
253253
var defaults = FieldDefaults;
254254

255+
if (fields == null || attributes == null || defaults == null)
256+
return null;
257+
258+
var ret = new Il2CppFieldReflectionData[FieldCount];
259+
for (var i = 0; i < FieldCount; i++)
260+
{
261+
ret[i] = new()
262+
{
263+
attributes = attributes![i],
264+
field = fields[i],
265+
defaultValue = defaults![i],
266+
indexInParent = i,
267+
fieldOffset = LibCpp2IlMain.Binary!.GetFieldOffsetFromIndex(TypeIndex, i, fields[i].FieldIndex, IsValueType, attributes[i].HasFlag(System.Reflection.FieldAttributes.Static))
268+
};
269+
}
270+
255271
return fields?
256-
.Select((t, i) => new Il2CppFieldReflectionData {attributes = attributes![i], field = t, defaultValue = defaults![i], indexInParent = i})
272+
.Select((t, i) => new Il2CppFieldReflectionData {})
257273
.ToArray();
258274
}
259275
}

LibCpp2IL/Reflection/Il2CppFieldReflectionData.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ public class Il2CppFieldReflectionData
99
public FieldAttributes attributes;
1010
public object? defaultValue;
1111
public int indexInParent;
12+
public int fieldOffset;
1213
}
1314
}

0 commit comments

Comments
 (0)