Introduce TargetString to eliminate text GC.

This commit is contained in:
2022-11-21 14:09:01 +08:00
parent 784c3fc338
commit 109b489104
4 changed files with 154 additions and 10 deletions

View File

@@ -4,6 +4,7 @@ using System;
using System.Collections.Generic;
using System.Reflection;
using RBeatTime = Cryville.Crtr.BeatTime;
using RTargetString = Cryville.Common.Buffers.TargetString;
namespace Cryville.Crtr {
public abstract class PropOp : PdtOperator {
@@ -45,6 +46,22 @@ namespace Cryville.Crtr {
_cb(GetOperand(0).AsString());
}
}
public class TargetString : PropOp {
readonly Func<RTargetString> _cb;
public TargetString(Func<RTargetString> cb) { _cb = cb; }
protected override unsafe void Execute() {
var target = _cb();
var op = GetOperand(0);
if (op.Type != PdtInternalType.String) throw new ArgumentException("Not a string");
var ptr = (byte*)op.TrustedAsOfLength(op.Length);
var len = *(int*)ptr;
target.Length = len;
var cptr = (char*)(ptr + sizeof(int));
for (int i = 0; i < len; i++)
target[i] = cptr[i];
target.Validate();
}
}
public class Identifier : PropOp {
readonly Action<int> _cb;
public Identifier(Action<int> cb) { _cb = cb; }