mirror-llvm-project/libc
Jackson Stogel a81db64570
[libc][cpp::string] Allocate fewer temp strings in operator= and += (#210895)
This PR generally updates `cpp::string` to avoid incidental allocations.
Specifically, it:

- Updates `opreator=(string_view)` to avoid allocating a temporary
string:
67ebc4b221/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.
- Makes the `string(string_view)` constructor explicit. Before, there
were non-obvious allocations because of the implicit conversion.

As a side effect, this PR has to more carefully handle self-assignment
and self-append. This PR updates append and assignment to avoid calling
`realloc` during append / assignment, as this may invalidate input
pointers held by `string_view` if they point to data held by the string.
This also fixes self-assignment, which previously didn't work, eg
`cpp::string s = "abc"; s = s;` would zero out `s`.
2026-07-26 07:25:50 -07:00
..
benchmarks [libc][benchmark] allow benchmark to be built without llvm support (#200951) 2026-06-25 19:16:08 +00:00
cmake [libc][termios] Make termios hermetic and fix its compatibility with glibc 2.42 or after. (#211039) 2026-07-24 13:31:41 -04:00
config [libc] Add missing sys/types.h integer and BSD/System V type definitions (#211861) 2026-07-24 21:49:38 +01:00
docs [libc][math] Implement half precision lgamma function (#192834) 2026-07-19 04:29:50 +03:00
examples [libc] Fix broken links in libc (#145199) 2025-06-23 15:51:43 -07:00
fuzzing [libc] Migrate printf_core from stdio/ to __support/. (#208303) 2026-07-21 14:35:24 -07:00
hdr [libc][termios] Make termios hermetic and fix its compatibility with glibc 2.42 or after. (#211039) 2026-07-24 13:31:41 -04:00
include [libc] Add symbolic constants for si_code values. (#211945) 2026-07-24 16:57:00 -07:00
lib [libc] Generate a stub for libpthread.a (#200908) 2026-06-15 23:35:20 -07:00
shared [libc][math] Implement half precision lgamma function (#192834) 2026-07-19 04:29:50 +03:00
src [libc][cpp::string] Allocate fewer temp strings in operator= and += (#210895) 2026-07-26 07:25:50 -07:00
startup [libc][NFC] Port raw syscall users to existing syscall_wrappers (#208039) 2026-07-17 14:23:39 -03:00
test [libc][cpp::string] Allocate fewer temp strings in operator= and += (#210895) 2026-07-26 07:25:50 -07:00
utils [libc][math] Implement half precision lgamma function (#192834) 2026-07-19 04:29:50 +03:00
.clang-tidy
.gitignore [libc][wctype] Create generation script for classification lookup tables (#172042) 2026-01-06 12:13:28 +01:00
CMakeLists.txt [libc][termios] Make termios hermetic and fix its compatibility with glibc 2.42 or after. (#211039) 2026-07-24 13:31:41 -04:00
LICENSE.TXT
Maintainers.md [libc][freebsd] initialize freebsd support (#124459) 2026-05-19 13:04:34 -07:00
README.txt

LLVM libc
=========

This directory and its subdirectories contain source code for llvm-libc,
a retargetable implementation of the C standard library.

LLVM is open source software. You may freely distribute it under the terms of
the license agreement found in LICENSE.txt.