Use std::string_view in place of const std::string& #4300
Merged
Conversation
…meters Converts const std::string& parameters to std::string_view across mesh::to_type, the XDMF/HDF5/VTK I/O layer, common::Table/TimeLogger/timing, and the PETSc/SLEPc option-prefix and error-reporting helpers, avoiding unnecessary string copies/allocations for callers passing literals or substrings. Parameters that are stored, mutated in place, or are map/vector element types are left as std::string. Updates the two nanobind wrapper files that bind the changed functions directly to include the string_view caster. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Two real bugs left over from the const std::string& -> std::string_view conversion: - VTKFile.h: the constructor declaration's last parameter had been mangled to `std::string_view;`, dropping the parameter name and closing paren entirely (a hard compile error). - xdmf_mesh.cpp: add_mesh's renamed parameter (name -> path_prefix) collided with a local variable of the same name computing the combined "/Mesh/<name>" path, causing a redefinition error; the stray "git" token in the initializer suggests this line was also corrupted in the same edit. Renamed the local to full_path_prefix. Also reformats the rest of the branch's files with clang-format, which had drifted out of compliance during the refactor. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This reverts commit f857f4d.
This reverts commit c9b113a.
Replace std::string/std::to_string + operator+ chains with std::format across mesh, fem, io, graph, refinement, common, and la, matching the existing usage elsewhere in the codebase. Also fixes a couple of latent bugs surfaced along the way: missing spaces in two error messages (Topology.cpp, dofmapbuilder.cpp) and math::det() reporting matrix data values instead of the matrix shape in its error message. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
GCC 12/13 spuriously flags common::Timer::_start_time (a std::optional<time_point>) as possibly uninitialized in graph/partitioners.cpp, triggered by inlining changes in Timer's destructor after TimeLogger::register_timing switched to std::string_view. Add -Wno-maybe-uninitialized alongside the existing GCC 12/13 workarounds for -Wno-array-bounds/-Wno-stringop-overflow. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
garth-wells
marked this pull request as ready for review
July 18, 2026 16:46
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.
Pass
std::string_viewin place ofconst std::string&to functions. This can avoid unnecessary (and rather hidden) creations ofstd::strings.To avoid numerous
std::string_view->std::stringconstructions inside functions, make much greater use ofstd::formatfor string concatenation. This also tidies up and simplifies many cases of string handling.Used Claude.