Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ltrzesniewski committed Dec 19, 2021
1 parent 1baaa66 commit 5685b60
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 21 deletions.
7 changes: 3 additions & 4 deletions src/PCRE.NET/Internal/CalloutInterop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,12 @@ public static void Prepare(ReadOnlySpan<char> subject,
}

public static void Prepare(ReadOnlySpan<char> subject,
InternalRegex regex,
PcreMatchBuffer buffer,
ref Native.buffer_match_input input,
out CalloutInteropInfo interopInfo,
PcreRefCalloutFunc callout,
nuint[] calloutOutputVector)
PcreRefCalloutFunc callout)
{
interopInfo = new CalloutInteropInfo(subject, regex, callout, calloutOutputVector);
interopInfo = new CalloutInteropInfo(subject, buffer.Regex, callout, buffer.CalloutOutputVector);

input.callout = _calloutHandlerFnPtr;
input.callout_data = interopInfo.ToPointer();
Expand Down
2 changes: 1 addition & 1 deletion src/PCRE.NET/Internal/InternalRegex.cs
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ public void BufferMatch(ref PcreRefMatch match,
ThrowMatchBufferDisposed();

if (callout != null)
CalloutInterop.Prepare(subject, this, ref input, out calloutInterop, callout, buffer.CalloutOutputVector);
CalloutInterop.Prepare(subject, buffer, ref input, out calloutInterop, callout);

Native.buffer_match(&input, &result);
}
Expand Down
16 changes: 8 additions & 8 deletions src/PCRE.NET/PcreMatchBuffer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace PCRE
/// </remarks>
public sealed unsafe class PcreMatchBuffer : IDisposable
{
private readonly InternalRegex _regex;
internal readonly InternalRegex Regex;
private readonly int _outputVectorSize;

internal IntPtr NativeBuffer;
Expand All @@ -24,12 +24,12 @@ public sealed unsafe class PcreMatchBuffer : IDisposable

internal PcreMatchBuffer(InternalRegex regex, PcreMatchSettings settings)
{
_regex = regex;
Regex = regex;
_outputVectorSize = regex.OutputVectorSize;

CalloutOutputVector = new nuint[_outputVectorSize];

_regex.TryGetCalloutInfoByPatternPosition(0); // Make sure callout info is initialized
Regex.TryGetCalloutInfoByPatternPosition(0); // Make sure callout info is initialized

var info = new Native.match_buffer_info
{
Expand Down Expand Up @@ -147,9 +147,9 @@ public PcreRefMatch Match(ReadOnlySpan<char> subject, int startIndex, PcreMatchO
if (unchecked((uint)startIndex > (uint)subject.Length))
ThrowInvalidStartIndex();

var match = new PcreRefMatch(_regex, GetOutputVectorSpan());
var match = new PcreRefMatch(Regex, GetOutputVectorSpan());

_regex.BufferMatch(
Regex.BufferMatch(
ref match,
subject,
this,
Expand Down Expand Up @@ -203,7 +203,7 @@ public RefMatchEnumerable Matches(ReadOnlySpan<char> subject, int startIndex, Pc
/// Returns the regex pattern.
/// </summary>
public override string ToString()
=> _regex.Pattern;
=> Regex.Pattern;

private static void ThrowInvalidStartIndex()
=> throw new ArgumentOutOfRangeException("Invalid start index.", default(Exception));
Expand Down Expand Up @@ -278,9 +278,9 @@ public bool MoveNext()

if (!_match.IsInitialized)
{
_match = new PcreRefMatch(_buffer._regex, _buffer.GetOutputVectorSpan());
_match = new PcreRefMatch(_buffer.Regex, _buffer.GetOutputVectorSpan());

_buffer._regex.BufferMatch(
_buffer.Regex.BufferMatch(
ref _match,
_subject,
_buffer,
Expand Down
13 changes: 6 additions & 7 deletions src/PCRE.NET/PcreRefMatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public unsafe ref struct PcreRefMatch
private int _resultCode;
private char* _markPtr;

internal ReadOnlySpan<char> Subject;

/// <summary>
/// A function which returns an output value out of a match.
/// </summary>
Expand Down Expand Up @@ -53,6 +55,8 @@ internal PcreRefMatch(ReadOnlySpan<char> subject, InternalRegex regex, Span<nuin
_resultCode = oVector.Length / 2;
}

internal readonly bool IsInitialized => _regex != null;

/// <inheritdoc cref="PcreMatch.CaptureCount"/>
public readonly int CaptureCount => _regex?.CaptureCount ?? 0;

Expand All @@ -68,9 +72,6 @@ internal PcreRefMatch(ReadOnlySpan<char> subject, InternalRegex regex, Span<nuin
/// <param name="name">The name of the capturing group.</param>
public readonly PcreRefGroup this[string name] => GetGroup(name);

internal ReadOnlySpan<char> Subject;
internal readonly bool IsInitialized => _regex != null;

/// <inheritdoc cref="PcreMatch.Index"/>
public readonly int Index => _regex is not null && _resultCode is > 0 or PcreConstants.ERROR_PARTIAL
? (int)OutputVector[0]
Expand Down Expand Up @@ -214,14 +215,12 @@ internal void FirstMatch(ReadOnlySpan<char> subject,
internal void NextMatch(PcreMatchSettings settings,
PcreMatchOptions options,
PcreRefCalloutFunc? callout,
nuint[]? calloutOutputVector,
bool reuseOutputVector)
nuint[]? calloutOutputVector)
{
var startOfNextMatchIndex = GetStartOfNextMatchIndex();
var nextOptions = options.ToPatternOptions() | PcreConstants.NO_UTF_CHECK | (Length == 0 ? PcreConstants.NOTEMPTY_ATSTART : 0);

if (!reuseOutputVector)
OutputVector = Span<nuint>.Empty;
OutputVector = Span<nuint>.Empty;

_regex!.Match(
ref this,
Expand Down
2 changes: 1 addition & 1 deletion src/PCRE.NET/PcreRegex.Match.cs
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ public bool MoveNext()
}
else
{
_match.NextMatch(_settings, _options, _callout, null, false);
_match.NextMatch(_settings, _options, _callout, null);
}

if (_match.Success)
Expand Down

0 comments on commit 5685b60

Please sign in to comment.