Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New tokenization & integer parsing helpers #17962

Merged
merged 6 commits into from
Oct 29, 2024

Conversation

lhecker
Copy link
Member

@lhecker lhecker commented Sep 25, 2024

Reading through our existing patterns for integer parsing, I noticed
that we'd be better off returning them as optionals.
This also allowed me to improve the implementation to support integers
all the way up to their absolute maximum/minimum.

Furthermore, I noticed that prefix_split was unsound:
If the last needle character was the last character in the remaining
text, the remaining text would be updated to an empty string view.
The caller would then have no idea if there's 1 more token left
or if the string is truly empty.
To solve this, this PR introduces an iterator class. This will allow
it to be used in our VT parser code.

@lhecker lhecker added the Area-CodeHealth Issues related to code cleanliness, linting, rules, warnings, errors, static analysis, etc. label Sep 25, 2024
// Don't call operator*() twice per iteration.
// Since C++ has inflexible iterators we can't implement a split iterator efficiently:
// We essentially need a do-while loop but iterators only offer for() loop semantics.
// This forces us to either seek to the first token in the constructor and then again on
Copy link
Member

Choose a reason for hiding this comment

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

qq: why prefer the one that makes it unsafe/hazardous to handle, instead of the one that makes it safe?

Copy link
Member Author

Choose a reason for hiding this comment

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

An excellent point. I didn't even benchmark the two versions and what's not measured is not real. 😤

@@ -1009,7 +1009,7 @@ bool OutputStateMachineEngine::_GetOscSetColor(const std::wstring_view string,
}

std::vector<DWORD> newRgbs;
for (auto&& part : parts)
for (const auto part : parts)
Copy link
Member

Choose a reason for hiding this comment

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

auto&& should deduce const auto here, shouldn't it?

Copy link
Member Author

Choose a reason for hiding this comment

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

It should, and I'm sure it does, but the linter complains (incorrectly), so I just changed it.

@lhecker
Copy link
Member Author

lhecker commented Oct 10, 2024

CI passed but ARM64 is being a drama queen. 😅

@DHowett
Copy link
Member

DHowett commented Oct 10, 2024

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@carlos-zamora carlos-zamora merged commit fa82730 into main Oct 29, 2024
20 checks passed
@carlos-zamora carlos-zamora deleted the dev/lhecker/til-string-improvements branch October 29, 2024 18:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-CodeHealth Issues related to code cleanliness, linting, rules, warnings, errors, static analysis, etc.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants