Introduce IdentifierManager to improve PDT evaluator performance.
This commit is contained in:
@@ -74,4 +74,48 @@ namespace Cryville.Common.Pdt {
|
||||
return _etor.StackAlloc(type, _prmem, len);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// The signature of a <see cref="PdtOperator" />.
|
||||
/// </summary>
|
||||
public struct PdtOperatorSignature : IEquatable<PdtOperatorSignature> {
|
||||
/// <summary>
|
||||
/// The name of the operator.
|
||||
/// </summary>
|
||||
public int Name { get; private set; }
|
||||
/// <summary>
|
||||
/// The parameter count.
|
||||
/// </summary>
|
||||
public int ParamCount { get; private set; }
|
||||
readonly int _hash;
|
||||
/// <summary>
|
||||
/// Creates an operator signature.
|
||||
/// </summary>
|
||||
/// <param name="name">The name of the operator.</param>
|
||||
/// <param name="paramCount">The parameter count.</param>
|
||||
public PdtOperatorSignature(string name, int paramCount)
|
||||
: this(IdentifierManager.SharedInstance.Request(name), paramCount) { }
|
||||
/// <summary>
|
||||
/// Creates an operator signature.
|
||||
/// </summary>
|
||||
/// <param name="name">The identifier of the operator.</param>
|
||||
/// <param name="paramCount">The parameter count.</param>
|
||||
public PdtOperatorSignature(int name, int paramCount) {
|
||||
Name = name;
|
||||
ParamCount = paramCount;
|
||||
_hash = Name ^ ((ParamCount << 16) | (ParamCount >> 16));
|
||||
}
|
||||
public override bool Equals(object obj) {
|
||||
if (!(obj is PdtOperatorSignature)) return false;
|
||||
return Equals((PdtOperatorSignature)obj);
|
||||
}
|
||||
public bool Equals(PdtOperatorSignature other) {
|
||||
return Name == other.Name && ParamCount == other.ParamCount;
|
||||
}
|
||||
public override int GetHashCode() {
|
||||
return _hash;
|
||||
}
|
||||
public override string ToString() {
|
||||
return string.Format("{0}({1})", Name, ParamCount);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user