[all-commits] [llvm/llvm-project] e30a5d: [libc++][NFC] Simplify string a bit (#127135)
Peng Liu via All-commits
all-commits at lists.llvm.org
Sat Mar 15 19:11:18 PDT 2025
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: e30a5d657034c1cf7081be4601a39888c0c1f2a6
https://github.com/llvm/llvm-project/commit/e30a5d657034c1cf7081be4601a39888c0c1f2a6
Author: Peng Liu <winner245 at hotmail.com>
Date: 2025-03-15 (Sat, 15 Mar 2025)
Changed paths:
M libcxx/include/string
Log Message:
-----------
[libc++][NFC] Simplify string a bit (#127135)
This PR refactors `basic_string` a bit to simplify its implementation in
the following ways:
- Instead of manually checking whether a string is short or long,
followed by calling the specific functions (e.g., `__get_short_size()`,
`__get_long_size()`), we call the general functions (`size()`) to hide
the conditional checks and make the code more concise.
- Once a string is determined to be short or long, we directly call the
specific functions instead of the general versions to get rid of
unnecessary internal conditional checks. For example, for a long string,
we would directly call `{__set, __get}_long_pointer` instead of `{__set,
__get}_pointer()`.
- Variables that are defined in both the `if` and `else` branches are
now declared in a common scope to reduce redundancy.
- When the string size is calculated multiple times using
`traits_type::length(__s)`, a variable is introduced to store its
length. While modern compilers can optimize this with constant folding,
explicitly storing the length improves code readability and makes the
logic clearer.
- Fixed synopsis with missing default arguments.
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