Skip to content

Conversation

@stephentoub
Copy link
Member

Now that we're operating over a span that represents the full input from beginning to end, we no longer need to access runtextbeg/runtextend, we can use inputSpan.Slice(pos) instead of inputSpan.Slice(pos, end - pos), etc.

… generator

Now that we're operating over a span that represents the full input from beginning to end, we no longer need to access runtextbeg/runtextend, we can use inputSpan.Slice(pos) instead of inputSpan.Slice(pos, end - pos), etc.
@ghost
Copy link

ghost commented Mar 3, 2022

Tagging subscribers to this area: @dotnet/area-system-text-regularexpressions
See info in area-owners.md if you want to be subscribed.

Issue Details

Now that we're operating over a span that represents the full input from beginning to end, we no longer need to access runtextbeg/runtextend, we can use inputSpan.Slice(pos) instead of inputSpan.Slice(pos, end - pos), etc.

Author: stephentoub
Assignees: -
Labels:

area-System.Text.RegularExpressions

Milestone: 7.0.0

{
writer.WriteLine("int newlinePos = global::System.MemoryExtensions.IndexOf(inputSpan.Slice(pos), '\\n');");
using (EmitBlock(writer, "if (newlinePos < 0 || newlinePos + pos + 1 > end)"))
using (EmitBlock(writer, "if ((uint)newlinePos > inputSpan.Length - pos - 1)"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: I like the condensed check here, but I wonder if it might be harder to read than what we used to have. Would it make sense to add a comment above the if-block with the writer so that it is easier to understand for people when debugging the source generated code? If you think the check is to obvious as to what it is doing then I'm fine without a comment.

TransferSliceStaticPosToPos();
Ldloc(end);
Ldloca(inputSpan);
Call(s_spanGetLengthMethod);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: Since we do this a lot now, should we consider a Macro that does the inputSpan.Length similar to how we have one for SliceInputSpan?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are already a bunch of places where we get a span's length. If you think it's worth adding a helper for, we can go back through after and replace each pair of two calls with one call.

Copy link
Member

@joperezr joperezr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@EgorBo
Copy link
Member

EgorBo commented Mar 17, 2022

Improvements on alpine-x64 dotnet/perf-autofiling-issues#3976

@ghost ghost locked as resolved and limited conversation to collaborators Apr 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants