[libc-commits] [PATCH] D146660: [libc][NFC] move strcoll to strcmp template

Michael Jones via Phabricator via libc-commits libc-commits at lists.llvm.org
Wed Mar 22 14:12:58 PDT 2023


michaelrj created this revision.
michaelrj added reviewers: mcgrathr, sivachandra.
Herald added subscribers: libc-commits, mikhail.ramalho, ecnelises, tschuett.
Herald added projects: libc-project, All.
michaelrj requested review of this revision.

While locales are not implemented, strcoll is equivalent to strcmp. This
patch moves strcoll over to the strcmp internal implementation.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D146660

Files:
  libc/src/string/CMakeLists.txt
  libc/src/string/strcoll.cpp


Index: libc/src/string/strcoll.cpp
===================================================================
--- libc/src/string/strcoll.cpp
+++ libc/src/string/strcoll.cpp
@@ -9,14 +9,16 @@
 #include "src/string/strcoll.h"
 
 #include "src/__support/common.h"
+#include "src/string/memory_utils/strcmp_implementations.h"
 
 namespace __llvm_libc {
 
 // TODO: Add support for locales.
 LLVM_LIBC_FUNCTION(int, strcoll, (const char *left, const char *right)) {
-  for (; *left && *left == *right; ++left, ++right)
-    ;
-  return static_cast<int>(*left) - static_cast<int>(*right);
+  auto comp = [](char l, char r) -> int {
+    return static_cast<int>(l) - static_cast<int>(r);
+  };
+  return strcmp_implementation(left, right, comp);
 }
 
 } // namespace __llvm_libc
Index: libc/src/string/CMakeLists.txt
===================================================================
--- libc/src/string/CMakeLists.txt
+++ libc/src/string/CMakeLists.txt
@@ -145,6 +145,8 @@
     strcoll.cpp
   HDRS
     strcoll.h
+  DEPENDS
+    .memory_utils.strcmp_implementation
 )
 
 add_entrypoint_object(


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D146660.507502.patch
Type: text/x-patch
Size: 1083 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libc-commits/attachments/20230322/e008d31c/attachment.bin>


More information about the libc-commits mailing list