Skip to content

Commit

Permalink
small changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ieviev committed May 30, 2024
1 parent 2b9e7b2 commit 5ad6dc0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,7 @@ internal MatchingState(SymbolicRegexNode<TSet> node, uint prevCharKind)
}

/// <summary>
/// TODO: The CLR assigns an entire field for this byte which is a waste,
/// and the much more preferred way to use this is in _nullabilityArray in the matcher
/// but the current design relies on interfaces/flags and
/// using the MatchingState directly so this byte is a quick solution to cheapen
/// it there by ~30% as well without having to breaking it all to pieces.
/// removing IsNullableFor in other places requires major redesign
/// TODO: This is only used to speed up the existing architecture, ideally should be removed along with IsNullableFor
/// </summary>
internal readonly int NullabilityInfo;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ internal sealed partial class SymbolicRegexMatcher<TSet> : SymbolicRegexMatcher
/// <summary>Data and routines for skipping ahead to the next place a match could potentially start.</summary>
private readonly RegexFindOptimizations? _findOpts;

/// <summary>Dead end state to quickly return NoMatch</summary>
/// <summary>Dead end state to quickly return NoMatch, this could potentially be a constant</summary>
private readonly int _deadStateId;

/// <summary>Whether the pattern contains any anchor</summary>
Expand Down Expand Up @@ -663,6 +663,7 @@ private bool FindEndPositionDeltasDFANoSkipAscii(ReadOnlySpan<char> input, int l
/// TODO: this is essentially a stripped down version when there's no good prefix optimizations
/// i don't trust the compiler to optimize this and it makes a
/// ~50% difference in performance with removing unnecessary checks alone
///
/// </summary>
private bool FindEndPositionDeltasDFANoSkip(ReadOnlySpan<char> input, int lengthMinus1, RegexRunnerMode mode,
ref int posRef, int startStateId, ref int endPosRef, ref int endStateIdRef, ref int initialStatePosRef, ref int initialStatePosCandidateRef)
Expand All @@ -674,12 +675,19 @@ private bool FindEndPositionDeltasDFANoSkip(ReadOnlySpan<char> input, int length
byte[] mtlookup = _mintermClassifier.ByteLookup()!;
int endStateId = endStateIdRef;
int currStateId = startStateId;
// ldfld only once
int deadStateId = _deadStateId;
try
{
// Loop through each character in the input, transitioning from state to state for each.
// The goal is to make this loop as fast as it can possible be,
// every single piece of overhead should be removed here
// there should be not a single callvirt instruction in the loop
// ldfld only if necessary (e.g. a reference changes)
// no memory writes unless necessary
while (true)
{
if (currStateId == _deadStateId)
if (currStateId == deadStateId)
{
return true;
}
Expand Down Expand Up @@ -709,9 +717,7 @@ private bool FindEndPositionDeltasDFANoSkip(ReadOnlySpan<char> input, int length
}
// one off check for the final position
// this is just to move it out of the hot loop
if ((!_stateFlagsArray[currStateId].IsNullable() &&
!_stateArray[currStateId]!.IsNullableFor(
GetPositionKind(-1))))
if ((!_stateFlagsArray[currStateId].IsNullable() && IsNullableWithContext(currStateId, 0)))
{
return false;
}
Expand Down

0 comments on commit 5ad6dc0

Please sign in to comment.