Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions libc/src/string/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@ add_header_library(
HDRS
string_utils.h
DEPENDS
.memory_utils.inline_bzero
.memory_utils.inline_memcpy
libc.hdr.types.size_t
libc.include.stdlib
libc.hdr.limits_macros
libc.src.__support.CPP.bitset
libc.src.__support.CPP.type_traits
libc.src.__support.common
Expand Down
11 changes: 5 additions & 6 deletions libc/src/string/string_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@
#ifndef LLVM_LIBC_SRC_STRING_STRING_UTILS_H
#define LLVM_LIBC_SRC_STRING_STRING_UTILS_H

#include "hdr/limits_macros.h"
#include "hdr/types/size_t.h"
#include "src/__support/CPP/bitset.h"
#include "src/__support/CPP/type_traits.h" // cpp::is_same_v
#include "src/__support/macros/config.h"
#include "src/__support/macros/optimization.h" // LIBC_UNLIKELY
#include "src/string/memory_utils/inline_bzero.h"
#include "src/string/memory_utils/inline_memcpy.h"

namespace LIBC_NAMESPACE_DECL {
namespace internal {

template <typename Word> LIBC_INLINE constexpr Word repeat_byte(Word byte) {
constexpr size_t BITS_IN_BYTE = 8;
static_assert(CHAR_BIT == 8, "repeat_byte assumes a byte is 8 bits.");
constexpr size_t BITS_IN_BYTE = CHAR_BIT;
constexpr size_t BYTE_MASK = 0xff;
Word result = 0;
byte = byte & BYTE_MASK;
Expand Down Expand Up @@ -189,8 +189,7 @@ LIBC_INLINE char *string_token(char *__restrict src,
if (LIBC_UNLIKELY(src == nullptr && ((src = *saveptr) == nullptr)))
return nullptr;

static_assert(sizeof(char) == sizeof(cpp::byte),
"bitset of 256 assumes char is 8 bits");
static_assert(CHAR_BIT == 8, "bitset of 256 assumes char is 8 bits");
cpp::bitset<256> delimiter_set;
for (; *delimiter_string != '\0'; ++delimiter_string)
delimiter_set.set(static_cast<size_t>(*delimiter_string));
Expand Down Expand Up @@ -220,7 +219,7 @@ LIBC_INLINE size_t strlcpy(char *__restrict dst, const char *__restrict src,
if (!size)
return len;
size_t n = len < size - 1 ? len : size - 1;
inline_memcpy(dst, src, n);
__builtin_memcpy(dst, src, n);
dst[n] = '\0';
return len;
}
Expand Down
2 changes: 2 additions & 0 deletions libc/src/string/strsep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#include "src/__support/macros/null_check.h"
#include "src/string/string_utils.h"

#include "src/__support/common.h"

namespace LIBC_NAMESPACE_DECL {

LLVM_LIBC_FUNCTION(char *, strsep,
Expand Down
3 changes: 2 additions & 1 deletion utils/bazel/llvm-project-overlay/libc/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4188,9 +4188,10 @@ libc_support_library(
deps = [
":__support_common",
":__support_cpp_bitset",
":__support_cpp_type_traits",
":__support_macros_optimization",
":hdr_limits_macros",
":llvm_libc_types_size_t",
":string_memory_utils",
":types_size_t",
],
)
Expand Down
Loading