[libc-commits] [libc] Use an existing helper in wcspbrk.cpp (PR #150444)

via libc-commits libc-commits at lists.llvm.org
Thu Jul 24 08:48:38 PDT 2025


https://github.com/enh-google created https://github.com/llvm/llvm-project/pull/150444

None

>From 14b0d7758cd712063563d59f43fbf4964810ed4c Mon Sep 17 00:00:00 2001
From: enh-google <enh at google.com>
Date: Thu, 24 Jul 2025 11:48:07 -0400
Subject: [PATCH] Use an existing helper in wcspbrk.cpp

---
 libc/src/wchar/wcspbrk.cpp | 11 ++---------
 1 file changed, 2 insertions(+), 9 deletions(-)

diff --git a/libc/src/wchar/wcspbrk.cpp b/libc/src/wchar/wcspbrk.cpp
index a00ba9979a489..5d86a494bdf39 100644
--- a/libc/src/wchar/wcspbrk.cpp
+++ b/libc/src/wchar/wcspbrk.cpp
@@ -11,17 +11,10 @@
 #include "hdr/types/wchar_t.h"
 #include "src/__support/common.h"
 #include "src/__support/macros/null_check.h"
+#include "wchar_utils.h"
 
 namespace LIBC_NAMESPACE_DECL {
 
-bool contains_char(const wchar_t *str, wchar_t target) {
-  for (; *str != L'\0'; str++)
-    if (*str == target)
-      return true;
-
-  return false;
-}
-
 LLVM_LIBC_FUNCTION(const wchar_t *, wcspbrk,
                    (const wchar_t *src, const wchar_t *breakset)) {
   LIBC_CRASH_ON_NULLPTR(src);
@@ -29,7 +22,7 @@ LLVM_LIBC_FUNCTION(const wchar_t *, wcspbrk,
 
   // currently O(n * m), can be further optimized to O(n + m) with a hash set
   for (int src_idx = 0; src[src_idx] != 0; src_idx++)
-    if (contains_char(breakset, src[src_idx]))
+    if (internal::wcschr(breakset, src[src_idx]))
       return src + src_idx;
 
   return nullptr;



More information about the libc-commits mailing list