CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
65 lines
2.0 KiB
ReStructuredText
65 lines
2.0 KiB
ReStructuredText
.. title:: clang-tidy - performance-string-view-conversions
|
|
|
|
performance-string-view-conversions
|
|
===================================
|
|
|
|
Finds and removes redundant conversions from ``std::[w|u8|u16|u32]string_view``
|
|
to ``std::[...]string`` in call expressions expecting ``std::[...]string_view``.
|
|
|
|
Before:
|
|
|
|
.. code-block:: c++
|
|
|
|
void foo(int p1, std::string_view p2, double p3);
|
|
void bar(std::string_view sv) {
|
|
foo(42, std::string(sv), 3.14); // conversion to std::string is
|
|
// redundant as std::string_view
|
|
// is expected
|
|
foo(42, std::string(sv).c_str(), 2.71); // conversion to std::string and
|
|
// then to char* is redundant
|
|
// as std::string_view
|
|
// is expected
|
|
foo(42, std::string("foo"), 3.14); // conversion to std::string is
|
|
// redundant as std::string_view
|
|
// is expected
|
|
}
|
|
|
|
After:
|
|
|
|
.. code-block:: c++
|
|
|
|
void foo(int p1, std::string_view p2, double p3);
|
|
void bar(std::string_view sv) {
|
|
foo(42, sv, 3.14);
|
|
foo(42, sv, 2.71);
|
|
foo(42, "foo", 3.14);
|
|
}
|
|
|
|
Please note
|
|
-----------
|
|
|
|
Pattern ``std::string(sv).c_str()`` can be used intentionally to copy
|
|
the given string up to the null byte. If so, you may use ``NOLINT``
|
|
or rewrite your code:
|
|
|
|
Before:
|
|
|
|
.. code-block:: c++
|
|
|
|
void foo(int p1, std::string_view p2, double p3);
|
|
void bar(std::string_view sv) {
|
|
foo(42, std::string(sv).c_str(), 2.71); // warning is emitted
|
|
}
|
|
|
|
After:
|
|
|
|
.. code-block:: c++
|
|
|
|
void foo(int p1, std::string_view p2, double p3);
|
|
void bar(std::string_view sv) {
|
|
std::string s(sv);
|
|
// No warning emitted for the next 2 lines
|
|
foo(42, s.c_str(), 2.71); // explicit std::string variable used
|
|
foo(42, std::string(sv).c_str(), 2.71); // NOLINT(performance-string-view-conversions)
|
|
}
|