[libc-commits] [libc] [libc][wctype] Upstream zip utility from PtrHash-cc prototype to LLVM libc (PR #174759)
Muhammad Bassiouni via libc-commits
libc-commits at lists.llvm.org
Wed Jan 7 04:21:26 PST 2026
https://github.com/bassiounix created https://github.com/llvm/llvm-project/pull/174759
None
>From 5d386e8c39f3efffc050fbbc5b4f5eb5b70f4baa Mon Sep 17 00:00:00 2001
From: bassiounix <muhammad.m.bassiouni at gmail.com>
Date: Wed, 7 Jan 2026 14:12:46 +0200
Subject: [PATCH] [libc][wctype] Upstream zip utility from PtrHash-cc prototype
to LLVM libc
---
libc/src/__support/wctype/CMakeLists.txt | 2 +
.../wctype/conversion/CMakeLists.txt | 1 +
.../wctype/conversion/utils/CMakeLists.txt | 7 ++
.../__support/wctype/conversion/utils/zip.h | 74 +++++++++++++++++++
4 files changed, 84 insertions(+)
create mode 100644 libc/src/__support/wctype/conversion/CMakeLists.txt
create mode 100644 libc/src/__support/wctype/conversion/utils/CMakeLists.txt
create mode 100644 libc/src/__support/wctype/conversion/utils/zip.h
diff --git a/libc/src/__support/wctype/CMakeLists.txt b/libc/src/__support/wctype/CMakeLists.txt
index 48d9cd9d056c7..be2f5883afbde 100644
--- a/libc/src/__support/wctype/CMakeLists.txt
+++ b/libc/src/__support/wctype/CMakeLists.txt
@@ -1,3 +1,5 @@
+add_subdirectory(conversion)
+
add_header_library(
wctype_classification_utils
HDRS
diff --git a/libc/src/__support/wctype/conversion/CMakeLists.txt b/libc/src/__support/wctype/conversion/CMakeLists.txt
new file mode 100644
index 0000000000000..512d2b1553c8c
--- /dev/null
+++ b/libc/src/__support/wctype/conversion/CMakeLists.txt
@@ -0,0 +1 @@
+add_subdirectory(utils)
diff --git a/libc/src/__support/wctype/conversion/utils/CMakeLists.txt b/libc/src/__support/wctype/conversion/utils/CMakeLists.txt
new file mode 100644
index 0000000000000..2bda389065f38
--- /dev/null
+++ b/libc/src/__support/wctype/conversion/utils/CMakeLists.txt
@@ -0,0 +1,7 @@
+add_header_library(
+ zip
+ HDRS
+ zip.h
+ DEPENDS
+ libc.src.__support.CPP.tuple
+)
diff --git a/libc/src/__support/wctype/conversion/utils/zip.h b/libc/src/__support/wctype/conversion/utils/zip.h
new file mode 100644
index 0000000000000..723d50c9746ac
--- /dev/null
+++ b/libc/src/__support/wctype/conversion/utils/zip.h
@@ -0,0 +1,74 @@
+//===-- Internal utils for wctype conversion code - zip ---------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+// Helper iterator for zipping two containers together. `__support` code can not
+// have dependencies, so we implement a minimal zip here used internally.
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_WCTYPE_CONVERSION_UTILS_ZIP_H
+#define LLVM_LIBC_SRC___SUPPORT_WCTYPE_CONVERSION_UTILS_ZIP_H
+
+#include "src/__support/CPP/tuple.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+namespace internal_wctype_conversion_utils {
+
+namespace {
+
+template <typename It1, typename It2> class ZipIterator {
+public:
+ using value_type = cpp::tuple<It1, It2>;
+
+ LIBC_INLINE constexpr ZipIterator(It1 it1, It2 it2) : it1(it1), it2(it2) {}
+
+ LIBC_INLINE constexpr const ZipIterator &operator++() const {
+ ++it1;
+ ++it2;
+ return *this;
+ }
+
+ LIBC_INLINE constexpr bool operator!=(const ZipIterator &other) const {
+ return it1 != other.it1 && it2 != other.it2;
+ }
+
+ LIBC_INLINE constexpr auto operator*() const { return cpp::tie(*it1, *it2); }
+
+private:
+ mutable It1 it1;
+ mutable It2 it2;
+};
+
+template <typename Container1, typename Container2> class ZipWrapper {
+public:
+ LIBC_INLINE constexpr ZipWrapper(Container1 &c1, Container2 &c2)
+ : c1(c1), c2(c2) {}
+
+ LIBC_INLINE constexpr auto begin() const {
+ return ZipIterator(c1.begin(), c2.begin());
+ }
+ LIBC_INLINE constexpr auto end() const {
+ return ZipIterator(c1.end(), c2.end());
+ }
+
+private:
+ Container1 &c1;
+ Container2 &c2;
+};
+
+} // namespace
+
+// Helper `zip` function
+template <typename C1, typename C2>
+LIBC_INLINE static constexpr ZipWrapper<C1, C2> zip(C1 &c1, C2 &c2) {
+ return ZipWrapper<C1, C2>(c1, c2);
+}
+
+} // namespace internal_wctype_conversion_utils
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC___SUPPORT_WCTYPE_CONVERSION_UTILS_ZIP_H
More information about the libc-commits
mailing list