[libc-commits] [libc] 06f6a77 - [libc] Simplify wcscmp (#143457)
    via libc-commits 
    libc-commits at lists.llvm.org
       
    Tue Jun 10 11:24:22 PDT 2025
    
    
  
Author: Michael Jones
Date: 2025-06-10T11:24:18-07:00
New Revision: 06f6a771da10094cce79bf5d42d8213e1e2d3656
URL: https://github.com/llvm/llvm-project/commit/06f6a771da10094cce79bf5d42d8213e1e2d3656
DIFF: https://github.com/llvm/llvm-project/commit/06f6a771da10094cce79bf5d42d8213e1e2d3656.diff
LOG: [libc] Simplify wcscmp (#143457)
The implementation of wcscmp mimicked strcmp, but was more complicated
than necessary. This patch makes it simpler.
Added: 
    
Modified: 
    libc/src/wchar/wcscmp.cpp
Removed: 
    
################################################################################
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
        
    
    
More information about the libc-commits
mailing list