Skip to content

use std::string_view in string_utils#9005

Merged
tautschnig merged 1 commit into
developfrom
string_utils_string_view
May 27, 2026
Merged

use std::string_view in string_utils#9005
tautschnig merged 1 commit into
developfrom
string_utils_string_view

Conversation

@kroening
Copy link
Copy Markdown
Collaborator

This introduces std::string_view as a replacement for std::string parameters for the string utility functions in util/string_utils.h, in the hope of avoiding copies of string contents.

The change is designed not to break any usage of the functions; C++17 guarantees that there's an implicit conversion from std::string to std::string_view.

  • Each commit message has a non-empty body, explaining why the change was made.
  • n/a Methods or procedures I have added are documented, following the guidelines provided in CODING_STANDARD.md.
  • n/a The feature or user visible behaviour I have added or modified has been documented in the User Guide in doc/cprover-manual/
  • Regression or unit tests are included, or existing tests cover the modified code (in this case I have detailed which ones those are in the commit message).
  • n/a My commit message includes data points confirming performance improvements (if claimed).
  • My PR is restricted to a single feature or bugfix.
  • n/a White-space or formatting changes outside the feature-related changed lines are in commits of their own.

@kroening kroening force-pushed the string_utils_string_view branch 2 times, most recently from a6d99d2 to e81b174 Compare May 11, 2026 17:41
@codecov
Copy link
Copy Markdown

codecov Bot commented May 11, 2026

Codecov Report

❌ Patch coverage is 98.73418% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.57%. Comparing base (df24632) to head (c2db038).

Files with missing lines Patch % Lines
src/util/string_utils.cpp 83.33% 4 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #9005      +/-   ##
===========================================
- Coverage    80.57%   80.57%   -0.01%     
===========================================
  Files         1708     1710       +2     
  Lines       189217   189251      +34     
  Branches        73       73              
===========================================
+ Hits        152460   152487      +27     
- Misses       36757    36764       +7     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@tautschnig tautschnig force-pushed the string_utils_string_view branch from e81b174 to d1c39c7 Compare May 27, 2026 12:05
Widen the input-parameter types of strip_string, capitalize, both
split_string overloads, trim_from_last_delimiter, escape, and
escape_non_alnum from `const std::string &` to `std::string_view`,
using C++17's implicit `std::string` -> `std::string_view` conversion
to keep all existing callers compiling unchanged.

This widens the entry contracts so a future caller that doesn't
already have a `std::string` to hand (e.g. a `(ptr, len)` slice or a
substring of an existing string) can call these functions without
materialising one.  It does not in itself save any copies at the
current callsites, all of which already hold a `std::string`.

Returning views (`std::vector<std::string_view>` from `split_string`,
`std::string_view` from `strip_string`) was considered and not done:
both functions are commonly invoked with a temporary as the input
string, so a returned view would dangle.
@tautschnig tautschnig force-pushed the string_utils_string_view branch from d1c39c7 to c2db038 Compare May 27, 2026 14:10
@tautschnig tautschnig merged commit 468caef into develop May 27, 2026
60 of 63 checks passed
@tautschnig tautschnig deleted the string_utils_string_view branch May 27, 2026 21:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants