obj.getobjectの同一タグ・同一フレーム問い合わせをキャッシュし往復を削減

このコミットが含まれているのは:
routersys committed 2026-06-27 19:50:28 +09:00
1 親 42e0b2b0f7
コミット 69881878e4
3ファイル変更
+82 -15

検索条件に一致するファイルはありません

+19 -3
ファイルの表示
@@ -23,6 +23,11 @@ namespace LuaScript.Engine
private int _height;
private bool _alive;
private readonly byte[] _callbackTag = new byte[NativeProtocol.CallbackTagMax];
private readonly byte[] _lastCallbackTag = new byte[NativeProtocol.CallbackTagMax];
private int _lastCallbackTagLength = -1;
private string _lastCallbackTagText = string.Empty;
public LuaJitWorker(string nativeDir)
{
_nativeDir = nativeDir;
@@ -114,9 +119,8 @@ namespace LuaScript.Engine
{
int frame = view.ReadInt32(NativeProtocol.OffCallbackFrame);
int tagLen = Math.Clamp(view.ReadInt32(NativeProtocol.OffCallbackTagLen), 0, NativeProtocol.CallbackTagMax);
var tagBytes = new byte[tagLen];
view.ReadArray(NativeProtocol.CallbackTagOffset, tagBytes, 0, tagLen);
string tag = Encoding.UTF8.GetString(tagBytes);
view.ReadArray(NativeProtocol.CallbackTagOffset, _callbackTag, 0, tagLen);
string tag = ResolveTag(tagLen);
SceneObjectInfo? info;
try { info = resolveObject(tag, frame); }
@@ -141,6 +145,18 @@ namespace LuaScript.Engine
}
}
private string ResolveTag(int tagLen)
{
if (tagLen == _lastCallbackTagLength &&
_callbackTag.AsSpan(0, tagLen).SequenceEqual(_lastCallbackTag.AsSpan(0, tagLen)))
return _lastCallbackTagText;
_lastCallbackTagText = Encoding.UTF8.GetString(_callbackTag, 0, tagLen);
_callbackTag.AsSpan(0, tagLen).CopyTo(_lastCallbackTag);
_lastCallbackTagLength = tagLen;
return _lastCallbackTagText;
}
private void EnsureWorker(int width, int height)
{
if (_alive && _process is { HasExited: false } && _width == width && _height == height)