Skip to content

Conversation

enh-google
Copy link
Contributor

No description provided.

@llvmbot llvmbot added the libc label Jul 24, 2025
@llvmbot
Copy link
Member

llvmbot commented Jul 24, 2025

@llvm/pr-subscribers-libc

Author: None (enh-google)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/150444.diff

1 Files Affected:

  • (modified) libc/src/wchar/wcspbrk.cpp (+2-9)
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;

@lntue lntue changed the title Use an existing helper in wcspbrk.cpp [libc] Use an existing helper in wcspbrk.cpp Jul 24, 2025
@enh-google
Copy link
Contributor Author

huh. internal::wcschr() has its arguments the opposite way round from wcschr(). deliberate or accidental? (that is: "should i change the caller or the callee?")

@sribee8
Copy link
Contributor

sribee8 commented Jul 24, 2025

huh. internal::wcschr() has its arguments the opposite way round from wcschr(). deliberate or accidental? (that is: "should i change the caller or the callee?")

the internal function was initially called something else- renaming it might be more optimal since the internal returns a bool while the public function returns a pointer and it is not being used by the public wcschr function

@enh-google
Copy link
Contributor Author

(see #150661 for the fuller cleanup.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants