Optimize GC for PropSrc.

This commit is contained in:
2022-12-25 22:20:46 +08:00
parent e589e37640
commit 44180c7e0f
3 changed files with 49 additions and 38 deletions

View File

@@ -928,25 +928,25 @@ namespace Cryville.Crtr {
public class VectorSrc : PropSrc {
readonly Func<Vector> _cb;
public VectorSrc(Func<Vector> cb) { _cb = cb; }
protected override unsafe void InternalGet(out int type, out byte[] value) {
protected override unsafe int InternalGet() {
var arr = _cb().ToArray();
if (arr.Length == 1) {
type = PdtInternalType.Number;
value = new byte[sizeof(float)];
fixed (byte* ptr = value) {
buf = new byte[sizeof(float)];
fixed (byte* ptr = buf) {
*(float*)ptr = arr[0];
}
return PdtInternalType.Number;
}
else {
type = PdtInternalType.Vector;
value = new byte[sizeof(float) * arr.Length + sizeof(int)];
fixed (byte* rptr = value) {
buf = new byte[sizeof(float) * arr.Length + sizeof(int)];
fixed (byte* rptr = buf) {
var ptr = (float*)rptr;
for (int i = 0; i < arr.Length; i++, ptr++) {
*ptr = arr[i];
}
*(int*)ptr = PdtInternalType.Number;
}
return PdtInternalType.Vector;
}
}
}