[libcxx-commits] [libcxx] 378cd9a - [libc++] Avoid using ranges::upper_bound in <format> (#186781)

via libcxx-commits libcxx-commits at lists.llvm.org
Thu Apr 23 02:27:10 PDT 2026


Author: Nikolas Klauser
Date: 2026-04-23T11:27:06+02:00
New Revision: 378cd9a307c266ea3e5b8b0439cfc63f3c56f630

URL: https://github.com/llvm/llvm-project/commit/378cd9a307c266ea3e5b8b0439cfc63f3c56f630
DIFF: https://github.com/llvm/llvm-project/commit/378cd9a307c266ea3e5b8b0439cfc63f3c56f630.diff

LOG: [libc++] Avoid using ranges::upper_bound in <format> (#186781)

The `ranges` algorithms take a significant time to instantiate.
Replacing `ranges::upper_bound` with `std::upper_bound` reduces the time
to parse `<format>` by ~50ms, or 10%.

Added: 
    

Modified: 
    libcxx/include/__format/escaped_output_table.h
    libcxx/utils/generate_escaped_output_table.py

Removed: 
    


################################################################################
diff  --git a/libcxx/include/__format/escaped_output_table.h b/libcxx/include/__format/escaped_output_table.h
index 1401b4637d839..a62c715811a0c 100644
--- a/libcxx/include/__format/escaped_output_table.h
+++ b/libcxx/include/__format/escaped_output_table.h
@@ -61,9 +61,10 @@
 #ifndef _LIBCPP___FORMAT_ESCAPED_OUTPUT_TABLE_H
 #define _LIBCPP___FORMAT_ESCAPED_OUTPUT_TABLE_H
 
-#include <__algorithm/ranges_upper_bound.h>
+#include <__algorithm/upper_bound.h>
 #include <__config>
 #include <__cstddef/ptr
diff _t.h>
+#include <__iterator/access.h>
 #include <cstdint>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
@@ -868,7 +869,7 @@ _LIBCPP_HIDE_FROM_ABI inline constexpr uint32_t __entries[735] = {
   if (__code_point >= 0x000323b0)
     return true;
 
-  ptr
diff _t __i = std::ranges::upper_bound(__entries, (__code_point << 14) | 0x3fffu) - __entries;
+  ptr
diff _t __i = std::upper_bound(std::begin(__entries), std::end(__entries), (__code_point << 14) | 0x3fffu) - __entries;
   if (__i == 0)
     return false;
 

diff  --git a/libcxx/utils/generate_escaped_output_table.py b/libcxx/utils/generate_escaped_output_table.py
index 6be7d128ed5f1..30583dd8cdc85 100755
--- a/libcxx/utils/generate_escaped_output_table.py
+++ b/libcxx/utils/generate_escaped_output_table.py
@@ -142,7 +142,7 @@ def compactPropertyRanges(input: list[PropertyRange]) -> list[PropertyRange]:
   if (__code_point >= 0x{unallocated:08x})
     return true;
 
-  ptr
diff _t __i = std::ranges::upper_bound(__entries, (__code_point << 14) | 0x3fffu) - __entries;
+  ptr
diff _t __i = std::upper_bound(std::begin(__entries), std::end(__entries), (__code_point << 14) | 0x3fffu) - __entries;
   if (__i == 0)
     return false;
 
@@ -216,9 +216,10 @@ def compactPropertyRanges(input: list[PropertyRange]) -> list[PropertyRange]:
 #ifndef _LIBCPP___FORMAT_ESCAPED_OUTPUT_TABLE_H
 #define _LIBCPP___FORMAT_ESCAPED_OUTPUT_TABLE_H
 
-#include <__algorithm/ranges_upper_bound.h>
+#include <__algorithm/upper_bound.h>
 #include <__config>
 #include <__cstddef/ptr
diff _t.h>
+#include <__iterator/access.h>
 #include <cstdint>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)


        


More information about the libcxx-commits mailing list