1 //===-- str{,case}cmp implementation ----------------------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_LIBC_SRC_STRING_MEMORY_UTILS_INLINE_STRCMP_H
10 #define LLVM_LIBC_SRC_STRING_MEMORY_UTILS_INLINE_STRCMP_H
14 namespace LIBC_NAMESPACE
{
16 template <typename Comp
>
17 LIBC_INLINE
constexpr int inline_strcmp(const char *left
, const char *right
,
19 // TODO: Look at benefits for comparing words at a time.
20 for (; *left
&& !comp(*left
, *right
); ++left
, ++right
)
22 return comp(*reinterpret_cast<const unsigned char *>(left
),
23 *reinterpret_cast<const unsigned char *>(right
));
26 template <typename Comp
>
27 LIBC_INLINE
constexpr int inline_strncmp(const char *left
, const char *right
,
28 size_t n
, Comp
&&comp
) {
32 // TODO: Look at benefits for comparing words at a time.
33 for (; n
> 1; --n
, ++left
, ++right
) {
35 if (!comp(lc
, '\0') || comp(lc
, *right
))
38 return comp(*reinterpret_cast<const unsigned char *>(left
),
39 *reinterpret_cast<const unsigned char *>(right
));
42 } // namespace LIBC_NAMESPACE
44 #endif // LLVM_LIBC_SRC_STRING_MEMORY_UTILS_INLINE_STRCMP_H