Introduce IntKeyedDictionary to improve performance.

This commit is contained in:
2023-03-24 17:06:47 +08:00
parent 89f391f040
commit e2c683567e
18 changed files with 1274 additions and 94 deletions

View File

@@ -1,4 +1,5 @@
using Cryville.Common;
using Cryville.Common.Collections.Specialized;
using Cryville.Common.Math;
using Cryville.Common.Pdt;
using Cryville.Crtr.Event;
@@ -10,7 +11,7 @@ using UnityEngine;
namespace Cryville.Crtr {
public class PdtEvaluator : PdtEvaluatorBase {
static readonly Dictionary<PdtOperatorSignature, PdtOperator> _shortops = new Dictionary<PdtOperatorSignature, PdtOperator>();
readonly Dictionary<int, PdtOperator> _ctxops = new Dictionary<int, PdtOperator>();
readonly IntKeyedDictionary<PdtOperator> _ctxops = new IntKeyedDictionary<PdtOperator>();
static readonly byte[] _nullbuf = new byte[0];
readonly byte[] _numbuf = new byte[4];
@@ -31,13 +32,12 @@ namespace Cryville.Crtr {
else if (name == _var_false) { LoadNum(0); type = PdtInternalType.Number; value = _numbuf; }
else if (name == _var_null) { LoadIdent(0); type = PdtInternalType.Undefined; value = _numbuf; }
else {
var id = new Identifier(name);
PropSrc prop; SkinVariable variable;
if (ContextEvent != null && ContextEvent.PropSrcs.TryGetValue(name, out prop)) {
prop.Get(out type, out value);
}
else if (ContextState != null && ChartPlayer.motionRegistry.ContainsKey(id)) {
_vec = ContextState.GetRawValue(id);
else if (ContextState != null && ChartPlayer.motionRegistry.ContainsKey(new Identifier(name))) {
_vec = ContextState.GetRawValue(name);
_vecsrc.Invalidate();
_vecsrc.Get(out type, out value);
}
@@ -121,12 +121,12 @@ namespace Cryville.Crtr {
public void ContextCascadeDiscardBlock() {
ContextCascadeBlocks.Pop();
}
readonly Dictionary<int, PropSrc>[] ContextCascade = new Dictionary<int, PropSrc>[256];
readonly IntKeyedDictionary<PropSrc>[] ContextCascade = new IntKeyedDictionary<PropSrc>[256];
int _cascadeHeight;
public void ContextCascadeInsert() {
ContextCascade[_cascadeHeight++].Clear();
}
public void ContextCascadeInsert(Dictionary<int, PropSrc> srcs) {
public void ContextCascadeInsert(IReadOnlyDictionary<int, PropSrc> srcs) {
ContextCascadeInsert();
foreach (var src in srcs) ContextCascadeUpdate(src.Key, src.Value);
}
@@ -136,7 +136,7 @@ namespace Cryville.Crtr {
public PropSrc ContextCascadeLookup(int name) {
PropSrc result;
for (int i = _cascadeHeight - 1; i >= ContextCascadeBlocks.Peek(); i--) {
Dictionary<int, PropSrc> cas = ContextCascade[i];
var cas = ContextCascade[i];
if (cas.TryGetValue(name, out result)) {
return result;
}
@@ -149,7 +149,7 @@ namespace Cryville.Crtr {
public PdtEvaluator() {
ContextCascadeBlocks.Push(0);
for (int i = 0; i < ContextCascade.Length; i++) ContextCascade[i] = new Dictionary<int, PropSrc>();
for (int i = 0; i < ContextCascade.Length; i++) ContextCascade[i] = new IntKeyedDictionary<PropSrc>();
_vecsrc = new VectorSrc(() => _vec);
_ctxops.Add(IdentifierManager.SharedInstance.Request("screen_edge"), new func_screen_edge(() => ContextTransform));