Skip to content

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. 😤


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 DHowett requested a review from carlos-zamora October 10, 2024 23:10
@DHowett
Copy link
Member

DHowett commented Oct 10, 2024

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@carlos-zamora carlos-zamora merged commit fa82730 into main Oct 29, 2024
@carlos-zamora carlos-zamora deleted the dev/lhecker/til-string-improvements branch October 29, 2024 18:55
DHowett added a commit to nukoseer/terminal that referenced this pull request Dec 5, 2024
@github-project-automation github-project-automation bot moved this to To Cherry Pick in 1.22 Servicing Pipeline Apr 24, 2025
@DHowett DHowett moved this from To Cherry Pick to Cherry Picked in 1.22 Servicing Pipeline Apr 24, 2025
DHowett pushed a commit that referenced this pull request Apr 24, 2025
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.

(cherry picked from commit fa82730)
Service-Card-Id: PVTI_lADOAF3p4s4AmhmQzgZtkTk
Service-Version: 1.22
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

Status: Cherry Picked

Development

Successfully merging this pull request may close these issues.

5 participants