[libc-commits] [libc] [libc] Simplify wcscmp (PR #143457)
via libc-commits
libc-commits at lists.llvm.org
Mon Jun 9 16:20:17 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-libc
Author: Michael Jones (michaelrj-google)
<details>
<summary>Changes</summary>
The implementation of wcscmp mimicked strcmp, but was more complicated
than necessary. This patch makes it simpler.
---
Full diff: https://github.com/llvm/llvm-project/pull/143457.diff
1 Files Affected:
- (modified) libc/src/wchar/wcscmp.cpp (+2-4)
``````````diff
diff --git a/libc/src/wchar/wcscmp.cpp b/libc/src/wchar/wcscmp.cpp
index f285efd905390..48c8b3be6c701 100644
--- a/libc/src/wchar/wcscmp.cpp
+++ b/libc/src/wchar/wcscmp.cpp
@@ -19,12 +19,10 @@ LLVM_LIBC_FUNCTION(int, wcscmp, (const wchar_t *left, const wchar_t *right)) {
LIBC_CRASH_ON_NULLPTR(left);
LIBC_CRASH_ON_NULLPTR(right);
- auto comp = [](wchar_t l, wchar_t r) -> int { return l - r; };
-
- for (; *left && !comp(*left, *right); ++left, ++right)
+ for (; *left && (*left == *right); ++left, ++right)
;
- return comp(*left, *right);
+ return *left - *right;
}
} // namespace LIBC_NAMESPACE_DECL
``````````
</details>
https://github.com/llvm/llvm-project/pull/143457
More information about the libc-commits
mailing list