[all-commits] [llvm/llvm-project] a10d30: [libc][cpp::string] Don't allocate a string in ope...

Jackson Stogel via All-commits all-commits at lists.llvm.org
Mon Jul 13 17:31:37 PDT 2026


  Branch: refs/heads/users/jtstogel/realpath/string-view-assign
  Home:   https://github.com/llvm/llvm-project
  Commit: a10d3081ca04d8b7a3ef24c85f3b233adac97f3d
      https://github.com/llvm/llvm-project/commit/a10d3081ca04d8b7a3ef24c85f3b233adac97f3d
  Author: jtstogel <jtstogel at gmail.com>
  Date:   2026-07-13 (Mon, 13 Jul 2026)

  Changed paths:
    M libc/src/__support/CPP/CMakeLists.txt
    M libc/src/__support/CPP/string.h
    M utils/bazel/llvm-project-overlay/libc/BUILD.bazel

  Log Message:
  -----------
  [libc][cpp::string] Don't allocate a string in operator=(string_view)

This PR:

- Updates `opreator=(string_view)` to avoid allocating a temporary string: https://github.com/llvm/llvm-project/blob/67ebc4b221c3e94028b33004cd5cd08deee95048/libc/src/__support/CPP/string.h#L106-L108
- Changes `operator+=(const string&)` to accept a `string_view` so that strings may be appended without allocation.
- Adds asserts to make it clear that `cpp::string` does not support self assignment. Currently, `cpp::string s = "abc"; s = s;` will zero out the string.



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list