use std::string_view for safe_string2int#9009
Merged
Merged
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #9009 +/- ##
========================================
Coverage 80.56% 80.56%
========================================
Files 1707 1707
Lines 189118 189134 +16
Branches 73 73
========================================
+ Hits 152363 152385 +22
+ Misses 36755 36749 -6 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
9163e88 to
8ee5931
Compare
tautschnig
approved these changes
May 26, 2026
The variants of safe_string2int now accept an std::string_view, instead of an std::string, in the hope of avoiding copies. Pass std::string_view by value (not const-reference) in all safe and optional variants, following C++ Core Guidelines F.16 and standard library convention.
Now that safe_string2unsigned and safe_string2size_t accept
std::string_view, call sites that previously allocated a temporary
std::string via std::string::substr() can use the non-allocating
std::string_view::substr() instead. Convert three such sites:
- src/memory-analyzer/analyze_symbol.cpp (two occurrences):
address_string.substr(2) allocated; string_view{...}.substr(2)
returns a view into the existing string.
- src/goto-instrument/skip_loops.cpp:
val.substr(delim+1) allocated; string_view{val}.substr(delim+1)
avoids the copy.
- src/goto-analyzer/taint_parser.cpp:
std::string(where, 9, npos) allocated; string_view{where}.substr(9)
avoids the copy.
Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The variants of
safe_string2intnow accept anstd::string_view, instead of an std::string, in the hope of avoiding copies.