public static RangeBoundaryFrom <T> AdjustAndCreate(T?value, RangeBoundaryFromKind boundaryKind) { DebugCode.AssertArgument( boundaryKind == RangeBoundaryFromKind.Inclusive || boundaryKind == RangeBoundaryFromKind.Exclusive, nameof(boundaryKind), "The boundary kind should be be either Inclusive or Exclusive"); if (_hasNaN && !_equalsFunc(value, value)) { value = default; boundaryKind = RangeBoundaryFromKind.Empty; } if (_hasNegativeInfinity && _equalsFunc(value, _negativeInfinity)) { value = default; boundaryKind = RangeBoundaryFromKind.Infinite; } if (_hasPositiveInfinity && _equalsFunc(value, _positiveInfinity)) { throw CodeExceptions.Argument(nameof(value), "The positive infinity value should not be used for From boundaries."); } if (value == null && boundaryKind != RangeBoundaryFromKind.Empty) { boundaryKind = RangeBoundaryFromKind.Infinite; } #pragma warning disable 618 // Validation not required: value and kind are adjusted return(new RangeBoundaryFrom <T>(value, boundaryKind, SkipsArgValidation)); #pragma warning restore 618 }
/// <summary>Initializes a new instance of the <see cref="TargetSourceLines"/> class.</summary> /// <param name="targetMethodHandle">Benchmark target method handle.</param> /// <param name="primaryAttributeLineNumber">Number of source line that contain primary annotation attribute.</param> /// <param name="attributeCandidateLineNumbers">Range of source lines that may contain attribute annotations.</param> /// <param name="attributeLineNumbers">Source lines that contain attribute annotations.</param> public TargetSourceLines( RuntimeMethodHandle targetMethodHandle, int primaryAttributeLineNumber, Range <int> attributeCandidateLineNumbers, Dictionary <RuntimeTypeHandle, int> attributeLineNumbers) { Code.InRange(primaryAttributeLineNumber, nameof(primaryAttributeLineNumber), 1, int.MaxValue); Code.AssertArgument( Range.Create(1, int.MaxValue).Contains(attributeCandidateLineNumbers), nameof(attributeCandidateLineNumbers), "Incorrect candidate line numbers range."); Code.AssertArgument( attributeCandidateLineNumbers.Contains(primaryAttributeLineNumber), nameof(primaryAttributeLineNumber), "Incorrect primery attribute line number."); DebugCode.AssertArgument( attributeLineNumbers.Values.All(l => attributeCandidateLineNumbers.Contains(l)), nameof(attributeLineNumbers), "Incorrect attribute line numbers."); TargetMethodHandle = targetMethodHandle; PrimaryAttributeLineNumber = primaryAttributeLineNumber; AttributeCandidateLineNumbers = attributeCandidateLineNumbers; _attributeLineNumbers = attributeLineNumbers; }
/// <summary>Constructs a new node</summary> /// <param name="begin">An edge start offset</param> /// <param name="end">An edge end offset</param> /// <param name="terminal">Is the edge terminates the string or not</param> /// <param name="children">A list of child nodes (edges)</param> public Node(int begin, int end, bool terminal, List <int> children = null) { DebugCode.AssertArgument(end >= 0, nameof(end), "end should be nonnegative"); Begin = begin; _end = terminal ? -end : end; Children = children; }
private IEnumerable <Suffix> AllFromNode(Node node, int length) { DebugCode.AssertArgument(length >= 0, nameof(length), "The length should be non-negative"); if (node.IsLeaf) // Empty subtree { if (length != 0) { yield return(CreateSuffix(node.End, length)); } yield break; } var branchStack = new Stack <BranchPoint>(); var branchPoint = new BranchPoint { Node = node, EdgeIndex = 0 }; for (;;) { DebugCode.BugIf(branchPoint.Node.Children == null, "branchPoint.Node.Children == null"); var edge = GetNode(branchPoint.Node.Children[branchPoint.EdgeIndex]); var edgeLength = edge.Length; length += edgeLength; if (!edge.IsTerminal) { branchPoint.Length = edgeLength; branchStack.Push(branchPoint); branchPoint = new BranchPoint { Node = edge, EdgeIndex = 0 }; continue; } // We have descended to a terminal edge. Let's produce a suffix yield return(CreateSuffix(edge.End, length)); // Move to the next suffix branch for (;;) { length -= edgeLength; var nextEdgeIndex = branchPoint.EdgeIndex + 1; DebugCode.BugIf(branchPoint.Node.Children == null, "branchPoint.Node.Children == null"); if (nextEdgeIndex < branchPoint.Node.Children.Count) { branchPoint.EdgeIndex = nextEdgeIndex; break; } // There is no more branches on the current level // Return to the previous level if (branchStack.Count == 0) { // no more branches to visit yield break; } branchPoint = branchStack.Pop(); edgeLength = branchPoint.Length; } } }
public static double Initialize(ref double target, double initializedValue, double uninitializedValue) { DebugCode.AssertArgument( initializedValue != uninitializedValue, nameof(initializedValue), "The values of uninitializedValue and initializedValue should not match"); var oldValue = Interlocked.CompareExchange(ref target, initializedValue, uninitializedValue); return(oldValue == uninitializedValue ? initializedValue : oldValue); }
/// <summary> /// Initialize the value referenced by <paramref name="target"/> in a thread-safe manner. /// The value is changed to <paramref name="initializedValue"/> only if the current value /// is <paramref name="uninitializedValue"/>. /// </summary> /// <typeparam name="T">Type of value.</typeparam> /// <param name="target">Reference to the target location.</param> /// <param name="initializedValue">The value to use if the target is currently uninitialized.</param> /// <param name="uninitializedValue">The uninitialized value.</param> /// <returns> /// The new value referenced by <paramref name="target"/>. /// Note that this is nearly always more useful than the usual /// return from <see cref="Interlocked.CompareExchange{T}(ref T, T, T)"/> /// because it saves another read to <paramref name="target"/>. /// </returns> public static T Initialize <T>(ref T target, T initializedValue, T uninitializedValue) where T : class { DebugCode.AssertArgument( initializedValue != uninitializedValue, nameof(initializedValue), "The values of uninitializedValue and initializedValue should not match"); var oldValue = Interlocked.CompareExchange(ref target, initializedValue, uninitializedValue); return(oldValue == uninitializedValue ? initializedValue : oldValue); }
public string Test02AssertionExcluded() { var result = ""; var count = Count; for (var i = 0; i < count; i++) { result = "!"; // ReSharper disable once InvocationIsSkipped DebugCode.AssertArgument(result == "!", nameof(result), $"{result} != '!'"); } return(result); }
/// <summary>Initializes a new instance of the <see cref="Message" /> class.</summary> /// <param name="runNumber">Number of the run the message belongs to.</param> /// <param name="runMessageNumber">Number of the message in the run.</param> /// <param name="elapsed">Time elapsed from the start of the benchmark.</param> /// <param name="messageSource">Source of the message.</param> /// <param name="messageSeverity">Severity of the message.</param> /// <param name="messageText">Text of the message.</param> /// <param name="hintText">Hints for the message.</param> public Message( int runNumber, int runMessageNumber, TimeSpan elapsed, MessageSource messageSource, MessageSeverity messageSeverity, [NotNull] string messageText, string hintText) { DebugCode.ValidCount(runNumber, nameof(runNumber)); DebugCode.ValidCount(runMessageNumber, nameof(runMessageNumber)); DebugCode.AssertArgument(elapsed > TimeSpan.Zero, nameof(messageSeverity), "Elapsed time should be positive."); DebugEnumCode.Defined(messageSource, nameof(messageSource)); DebugEnumCode.Defined(messageSeverity, nameof(messageSeverity)); Code.NotNullNorEmpty(messageText, nameof(messageText)); RunNumber = runNumber; RunMessageNumber = runMessageNumber; Elapsed = elapsed; MessageSource = messageSource; MessageSeverity = messageSeverity; MessageText = messageText; HintText = hintText; }