Skip to content

Commit 02cc05c

Browse files
committed
Use IConvertible for Const.
1 parent 3cc6c40 commit 02cc05c

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

jemalloc.Api/GenericMath.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ static GM()
2222
#endregion
2323

2424
#region Methods
25-
public static TData Const<TValue>(TValue v) where TValue : struct, IEquatable<TValue>, IComparable<TValue>
25+
public static TData Const<TValue>(TValue v) where TValue : struct, IEquatable<TValue>, IComparable<TValue>, IConvertible
2626
{
2727
return (TData) Convert.ChangeType(v, typeof(TData));
2828
}
@@ -142,13 +142,13 @@ public static TData Random()
142142
case UInt16 v:
143143
return Const(checked((ushort)Rng.Next(0, UInt16.MaxValue)));
144144
case Int64 v:
145-
return Const(checked((long)Rng.NextDouble() * Int64.MaxValue));
145+
return Const(checked((long)(Rng.NextDouble() * Int64.MaxValue)));
146146
case UInt64 v:
147-
return Const(checked((ulong)Rng.NextDouble() * UInt64.MaxValue));
147+
return Const(checked((ulong)(Rng.NextDouble() * UInt64.MaxValue)));
148148
case Single v:
149-
return Const(checked((Single)Rng.NextDouble() * Int64.MaxValue));
149+
return Const(checked(((Single)(Rng.NextDouble() * Int64.MaxValue))));
150150
case Double v:
151-
return Const(checked((double)Rng.NextDouble() * Int64.MaxValue));
151+
return Const(checked((((double)Rng.NextDouble() * Int64.MaxValue))));
152152

153153
default:
154154
throw new ArithmeticException();

jemalloc.Benchmarks/JemBenchmarkAttribute.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@
22
using System.Collections.Generic;
33
using System.Text;
44

5+
using BenchmarkDotNet.Configs;
6+
57
using BenchmarkDotNet.Attributes;
68

79
namespace jemalloc.Benchmarks
810
{
911
public class JemBenchmarkAttribute : BenchmarkAttribute
1012
{
13+
public static IConfig CurrentConfig { get; set; }
1114
}
1215
}

jemalloc.Cli/Program.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,7 @@ static void Benchmark<T>() where T : struct, IEquatable<T>, IComparable<T>, ICon
282282
Contract.Requires(BenchmarkOptions.ContainsKey("Sizes"));
283283
IConfig config = ManualConfig
284284
.Create(DefaultConfig.Instance);
285+
JemBenchmarkAttribute.CurrentConfig = config;
285286
try
286287
{
287288
switch ((Category)BenchmarkOptions["Category"])

0 commit comments

Comments
 (0)