|
14 | 14 | #ifndef LLVM_LIBC_SRC_STRING_STRING_UTILS_H |
15 | 15 | #define LLVM_LIBC_SRC_STRING_STRING_UTILS_H |
16 | 16 |
|
17 | | -#include "hdr/limits_macros.h" |
18 | 17 | #include "hdr/types/size_t.h" |
19 | 18 | #include "src/__support/CPP/bitset.h" |
20 | 19 | #include "src/__support/CPP/type_traits.h" // cpp::is_same_v |
21 | 20 | #include "src/__support/macros/config.h" |
22 | 21 | #include "src/__support/macros/optimization.h" // LIBC_UNLIKELY |
| 22 | +#include "src/string/memory_utils/inline_bzero.h" |
| 23 | +#include "src/string/memory_utils/inline_memcpy.h" |
23 | 24 |
|
24 | 25 | namespace LIBC_NAMESPACE_DECL { |
25 | 26 | namespace internal { |
26 | 27 |
|
27 | 28 | template <typename Word> LIBC_INLINE constexpr Word repeat_byte(Word byte) { |
28 | | - static_assert(CHAR_BIT == 8, "repeat_byte assumes a byte is 8 bits."); |
29 | | - constexpr size_t BITS_IN_BYTE = CHAR_BIT; |
| 29 | + constexpr size_t BITS_IN_BYTE = 8; |
30 | 30 | constexpr size_t BYTE_MASK = 0xff; |
31 | 31 | Word result = 0; |
32 | 32 | byte = byte & BYTE_MASK; |
@@ -189,7 +189,8 @@ LIBC_INLINE char *string_token(char *__restrict src, |
189 | 189 | if (LIBC_UNLIKELY(src == nullptr && ((src = *saveptr) == nullptr))) |
190 | 190 | return nullptr; |
191 | 191 |
|
192 | | - static_assert(CHAR_BIT == 8, "bitset of 256 assumes char is 8 bits"); |
| 192 | + static_assert(sizeof(char) == sizeof(cpp::byte), |
| 193 | + "bitset of 256 assumes char is 8 bits"); |
193 | 194 | cpp::bitset<256> delimiter_set; |
194 | 195 | for (; *delimiter_string != '\0'; ++delimiter_string) |
195 | 196 | delimiter_set.set(static_cast<size_t>(*delimiter_string)); |
@@ -219,7 +220,7 @@ LIBC_INLINE size_t strlcpy(char *__restrict dst, const char *__restrict src, |
219 | 220 | if (!size) |
220 | 221 | return len; |
221 | 222 | size_t n = len < size - 1 ? len : size - 1; |
222 | | - __builtin_memcpy(dst, src, n); |
| 223 | + inline_memcpy(dst, src, n); |
223 | 224 | dst[n] = '\0'; |
224 | 225 | return len; |
225 | 226 | } |
|
0 commit comments