Skip to content

Commit c90a8f3

Browse files
author
linzhijun
committed
fix
1 parent fd97e71 commit c90a8f3

2 files changed

Lines changed: 11 additions & 7 deletions

File tree

csharp/ToolGood.Algorithm/Internals/Functions/MathSum/Function_MODE.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ public override Operand Evaluate(AlgorithmEngine engine, Func<AlgorithmEngine, s
2323

2424
var dict = new Dictionary<decimal, int>();
2525
foreach (var item in list) {
26-
if (dict.ContainsKey(item)) {
27-
dict[item] += 1;
26+
if (dict.TryGetValue(item, out int count)) {
27+
dict[item] = count + 1;
2828
} else {
2929
dict[item] = 1;
3030
}

csharp/ToolGood.Algorithm/Operand.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,15 @@ public abstract class Operand
3939
/// Null
4040
/// </summary>
4141
public static readonly Operand Null = new OperandNull();
42-
private static readonly Operand[] IntCache = new Operand[256];
42+
43+
// 整数缓存范围: -1000 ~ 1000,共2001个值
44+
private const int IntCacheOffset = 1000;
45+
private const int IntCacheSize = 2001;
46+
private static readonly Operand[] IntCache = new Operand[IntCacheSize];
4347
static Operand()
4448
{
45-
for (int i = 0; i < 256; i++)
46-
IntCache[i] = new OperandInt(i - 128);
49+
for (int i = 0; i < IntCacheSize; i++)
50+
IntCache[i] = new OperandInt(i - IntCacheOffset);
4751
}
4852

4953
#region IsNull IsNumber IsText IsBoolean IsArray IsDate IsJson IsArrayJson IsError ErrorMsg
@@ -171,8 +175,8 @@ public static Operand Create(short obj)
171175
/// <returns></returns>
172176
public static Operand Create(int obj)
173177
{
174-
if (obj >= -128 && obj <= 127)
175-
return IntCache[obj + 128];
178+
if (obj >= -IntCacheOffset && obj <= IntCacheOffset)
179+
return IntCache[obj + IntCacheOffset];
176180
return new OperandInt(obj);
177181
}
178182

0 commit comments

Comments
 (0)