[libcxx-commits] [libcxx] [libc++] Avoid ranges::upper_bound inside <format> (PR #173150)
Nikolas Klauser via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Dec 24 01:38:55 PST 2025
https://github.com/philnik777 updated https://github.com/llvm/llvm-project/pull/173150
>From 919c9d952b5c1d0f94a39fface58d8f0ab559f8a Mon Sep 17 00:00:00 2001
From: Nikolas Klauser <nikolasklauser at berlin.de>
Date: Sat, 20 Dec 2025 12:54:42 +0100
Subject: [PATCH] [libc++] Avoid ranges::upper_bound inside <format>
---
libcxx/include/__format/extended_grapheme_cluster_table.h | 5 +++--
libcxx/include/__format/indic_conjunct_break_table.h | 5 +++--
libcxx/include/__format/width_estimation_table.h | 6 ++++--
libcxx/utils/generate_extended_grapheme_cluster_table.py | 5 +++--
libcxx/utils/generate_indic_conjunct_break_table.py | 5 +++--
libcxx/utils/generate_width_estimation_table.py | 6 ++++--
6 files changed, 20 insertions(+), 12 deletions(-)
diff --git a/libcxx/include/__format/extended_grapheme_cluster_table.h b/libcxx/include/__format/extended_grapheme_cluster_table.h
index f76e018df7ae1..6da07862d41e6 100644
--- a/libcxx/include/__format/extended_grapheme_cluster_table.h
+++ b/libcxx/include/__format/extended_grapheme_cluster_table.h
@@ -61,7 +61,7 @@
#ifndef _LIBCPP___FORMAT_EXTENDED_GRAPHEME_CLUSTER_TABLE_H
#define _LIBCPP___FORMAT_EXTENDED_GRAPHEME_CLUSTER_TABLE_H
-#include <__algorithm/ranges_upper_bound.h>
+#include <__algorithm/upper_bound.h>
#include <__config>
#include <__cstddef/ptrdiff_t.h>
#include <__iterator/access.h>
@@ -1647,7 +1647,8 @@ _LIBCPP_HIDE_FROM_ABI inline constexpr uint32_t __entries[1501] = {
// size. Then the upper bound for code point 3 will return the entry after
// 0x1810. After moving to the previous entry the algorithm arrives at the
// correct entry.
- ptrdiff_t __i = std::ranges::upper_bound(__entries, (__code_point << 11) | 0x7ffu) - __entries;
+ ptrdiff_t __i =
+ std::upper_bound(std::begin(__entries), std::end(__entries), (__code_point << 11) | 0x7ffu) - __entries;
if (__i == 0)
return __property::__none;
diff --git a/libcxx/include/__format/indic_conjunct_break_table.h b/libcxx/include/__format/indic_conjunct_break_table.h
index f48ea625908e9..d85782d73286b 100644
--- a/libcxx/include/__format/indic_conjunct_break_table.h
+++ b/libcxx/include/__format/indic_conjunct_break_table.h
@@ -61,7 +61,7 @@
#ifndef _LIBCPP___FORMAT_INDIC_CONJUNCT_BREAK_TABLE_H
#define _LIBCPP___FORMAT_INDIC_CONJUNCT_BREAK_TABLE_H
-#include <__algorithm/ranges_upper_bound.h>
+#include <__algorithm/upper_bound.h>
#include <__config>
#include <__cstddef/ptrdiff_t.h>
#include <__iterator/access.h>
@@ -531,7 +531,8 @@ _LIBCPP_HIDE_FROM_ABI inline constexpr uint32_t __entries[403] = {
// size. Then the upper bound for code point 3 will return the entry after
// 0x1810. After moving to the previous entry the algorithm arrives at the
// correct entry.
- ptrdiff_t __i = std::ranges::upper_bound(__entries, (__code_point << 11) | 0x7ffu) - __entries;
+ ptrdiff_t __i =
+ std::upper_bound(std::begin(__entries), std::end(__entries), (__code_point << 11) | 0x7ffu) - __entries;
if (__i == 0)
return __property::__none;
diff --git a/libcxx/include/__format/width_estimation_table.h b/libcxx/include/__format/width_estimation_table.h
index 0ea0b4f413a74..ae10a77a5b980 100644
--- a/libcxx/include/__format/width_estimation_table.h
+++ b/libcxx/include/__format/width_estimation_table.h
@@ -61,9 +61,10 @@
#ifndef _LIBCPP___FORMAT_WIDTH_ESTIMATION_TABLE_H
#define _LIBCPP___FORMAT_WIDTH_ESTIMATION_TABLE_H
-#include <__algorithm/ranges_upper_bound.h>
+#include <__algorithm/upper_bound.h>
#include <__config>
#include <__cstddef/ptrdiff_t.h>
+#include <__iterator/access.h>
#include <cstdint>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
@@ -255,7 +256,8 @@ inline constexpr uint32_t __table_upper_bound = 0x0003fffd;
if (__code_point < (__entries[0] >> 14))
return 1;
- ptrdiff_t __i = std::ranges::upper_bound(__entries, (__code_point << 14) | 0x3fffu) - __entries;
+ ptrdiff_t __i =
+ std::upper_bound(std::begin(__entries), std::end(__entries), (__code_point << 14) | 0x3fffu) - __entries;
if (__i == 0)
return 1;
diff --git a/libcxx/utils/generate_extended_grapheme_cluster_table.py b/libcxx/utils/generate_extended_grapheme_cluster_table.py
index eba88a4f48776..c64a5a00c4c16 100755
--- a/libcxx/utils/generate_extended_grapheme_cluster_table.py
+++ b/libcxx/utils/generate_extended_grapheme_cluster_table.py
@@ -135,7 +135,8 @@ def compactPropertyRanges(input: list[PropertyRange]) -> list[PropertyRange]:
// size. Then the upper bound for code point 3 will return the entry after
// 0x1810. After moving to the previous entry the algorithm arrives at the
// correct entry.
- ptrdiff_t __i = std::ranges::upper_bound(__entries, (__code_point << 11) | 0x7ffu) - __entries;
+ ptrdiff_t __i =
+ std::upper_bound(std::begin(__entries), std::end(__entries), (__code_point << 11) | 0x7ffu) - __entries;
if (__i == 0)
return __property::__none;
@@ -212,7 +213,7 @@ def compactPropertyRanges(input: list[PropertyRange]) -> list[PropertyRange]:
#ifndef _LIBCPP___FORMAT_EXTENDED_GRAPHEME_CLUSTER_TABLE_H
#define _LIBCPP___FORMAT_EXTENDED_GRAPHEME_CLUSTER_TABLE_H
-#include <__algorithm/ranges_upper_bound.h>
+#include <__algorithm/upper_bound.h>
#include <__config>
#include <__cstddef/ptrdiff_t.h>
#include <__iterator/access.h>
diff --git a/libcxx/utils/generate_indic_conjunct_break_table.py b/libcxx/utils/generate_indic_conjunct_break_table.py
index 580d8157ffebf..774a510849176 100755
--- a/libcxx/utils/generate_indic_conjunct_break_table.py
+++ b/libcxx/utils/generate_indic_conjunct_break_table.py
@@ -128,7 +128,8 @@ def compactPropertyRanges(input: list[PropertyRange]) -> list[PropertyRange]:
// size. Then the upper bound for code point 3 will return the entry after
// 0x1810. After moving to the previous entry the algorithm arrives at the
// correct entry.
- ptrdiff_t __i = std::ranges::upper_bound(__entries, (__code_point << 11) | 0x7ffu) - __entries;
+ ptrdiff_t __i =
+ std::upper_bound(std::begin(__entries), std::end(__entries), (__code_point << 11) | 0x7ffu) - __entries;
if (__i == 0)
return __property::__none;
@@ -205,7 +206,7 @@ def compactPropertyRanges(input: list[PropertyRange]) -> list[PropertyRange]:
#ifndef _LIBCPP___FORMAT_INDIC_CONJUNCT_BREAK_TABLE_H
#define _LIBCPP___FORMAT_INDIC_CONJUNCT_BREAK_TABLE_H
-#include <__algorithm/ranges_upper_bound.h>
+#include <__algorithm/upper_bound.h>
#include <__config>
#include <__cstddef/ptrdiff_t.h>
#include <__iterator/access.h>
diff --git a/libcxx/utils/generate_width_estimation_table.py b/libcxx/utils/generate_width_estimation_table.py
index f81f0ba77489e..618612c613741 100644
--- a/libcxx/utils/generate_width_estimation_table.py
+++ b/libcxx/utils/generate_width_estimation_table.py
@@ -170,7 +170,8 @@ def compactPropertyRanges(input: list[PropertyRange]) -> list[PropertyRange]:
if (__code_point < (__entries[0] >> 14))
return 1;
- ptrdiff_t __i = std::ranges::upper_bound(__entries, (__code_point << 14) | 0x3fffu) - __entries;
+ ptrdiff_t __i =
+ std::upper_bound(std::begin(__entries), std::end(__entries), (__code_point << 14) | 0x3fffu) - __entries;
if (__i == 0)
return 1;
@@ -244,9 +245,10 @@ def compactPropertyRanges(input: list[PropertyRange]) -> list[PropertyRange]:
#ifndef _LIBCPP___FORMAT_WIDTH_ESTIMATION_TABLE_H
#define _LIBCPP___FORMAT_WIDTH_ESTIMATION_TABLE_H
-#include <__algorithm/ranges_upper_bound.h>
+#include <__algorithm/upper_bound.h>
#include <__config>
#include <__cstddef/ptrdiff_t.h>
+#include <__iterator/access.h>
#include <cstdint>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
More information about the libcxx-commits
mailing list