Skip to content

Commit 44d3769

Browse files
authored
[libc++] Optimize ctype::to{lower,upper} (#145344)
``` ---------------------------------------------- Benchmark old new --------------------------- ------------------ BM_tolower_char<char> 1.64 ns 1.41 ns BM_tolower_char<wchar_t> 1.64 ns 1.41 ns BM_tolower_string<char> 32.4 ns 12.8 ns BM_tolower_string<wchar_t> 32.9 ns 15.1 ns BM_toupper_char<char> 1.63 ns 1.64 ns BM_toupper_char<wchar_t> 1.63 ns 1.41 ns BM_toupper_string<char> 32.2 ns 12.7 ns BM_toupper_string<wchar_t> 33.0 ns 15.1 ns ```
1 parent d0caf0d commit 44d3769

File tree

13 files changed

+115
-158
lines changed

13 files changed

+115
-158
lines changed

libcxx/docs/ReleaseNotes/21.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ Improvements and New Features
8585
- The ``flat_map::insert`` and ``flat_set::insert_range`` have been optimized, resulting in a performance improvement of up
8686
to 10x for inserting elements into a ``flat_map`` when the input range is a ``flat_map`` or a ``zip_view``.
8787

88+
- ``ctype::tolower`` and ``ctype::toupper`` have been optimized, resulting in a 2x performane improvement.
89+
8890
Deprecations and Removals
8991
-------------------------
9092

libcxx/include/__config

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -639,10 +639,6 @@ typedef __char32_t char32_t;
639639
# define _LIBCPP_HAS_C11_ALIGNED_ALLOC 1
640640
# endif
641641

642-
# if defined(__APPLE__) || defined(__FreeBSD__)
643-
# define _LIBCPP_HAS_DEFAULTRUNELOCALE
644-
# endif
645-
646642
# if defined(__APPLE__) || defined(__FreeBSD__)
647643
# define _LIBCPP_WCTYPE_IS_MASK
648644
# endif

libcxx/include/__locale

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -589,18 +589,6 @@ public:
589589
# endif
590590
_LIBCPP_HIDE_FROM_ABI const mask* table() const _NOEXCEPT { return __tab_; }
591591
static const mask* classic_table() _NOEXCEPT;
592-
# if defined(__GLIBC__) || defined(__EMSCRIPTEN__)
593-
static const int* __classic_upper_table() _NOEXCEPT;
594-
static const int* __classic_lower_table() _NOEXCEPT;
595-
# endif
596-
# if defined(__NetBSD__)
597-
static const short* __classic_upper_table() _NOEXCEPT;
598-
static const short* __classic_lower_table() _NOEXCEPT;
599-
# endif
600-
# if defined(__MVS__)
601-
static const unsigned short* __classic_upper_table() _NOEXCEPT;
602-
static const unsigned short* __classic_lower_table() _NOEXCEPT;
603-
# endif
604592

605593
protected:
606594
~ctype() override;

libcxx/include/__locale_dir/locale_base_api.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,6 @@
6464
// Character manipulation functions
6565
// --------------------------------
6666
// namespace __locale {
67-
// int __islower(int, __locale_t);
68-
// int __isupper(int, __locale_t);
6967
// int __isdigit(int, __locale_t); // required by the headers
7068
// int __isxdigit(int, __locale_t); // required by the headers
7169
// int __toupper(int, __locale_t);
@@ -208,11 +206,6 @@ __strtoull(const char* __nptr, char** __endptr, int __base, __locale_t __loc) {
208206
//
209207
// Character manipulation functions
210208
//
211-
# if defined(_LIBCPP_BUILDING_LIBRARY)
212-
inline _LIBCPP_HIDE_FROM_ABI int __islower(int __ch, __locale_t __loc) { return islower_l(__ch, __loc); }
213-
inline _LIBCPP_HIDE_FROM_ABI int __isupper(int __ch, __locale_t __loc) { return isupper_l(__ch, __loc); }
214-
# endif
215-
216209
inline _LIBCPP_HIDE_FROM_ABI int __isdigit(int __ch, __locale_t __loc) { return isdigit_l(__ch, __loc); }
217210
inline _LIBCPP_HIDE_FROM_ABI int __isxdigit(int __ch, __locale_t __loc) { return isxdigit_l(__ch, __loc); }
218211

libcxx/include/__locale_dir/support/bsd_like.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,6 @@ __strtoull(const char* __nptr, char** __endptr, int __base, __locale_t __loc) {
8989
//
9090
// Character manipulation functions
9191
//
92-
#if defined(_LIBCPP_BUILDING_LIBRARY)
93-
inline _LIBCPP_HIDE_FROM_ABI int __islower(int __c, __locale_t __loc) { return ::islower_l(__c, __loc); }
94-
95-
inline _LIBCPP_HIDE_FROM_ABI int __isupper(int __c, __locale_t __loc) { return ::isupper_l(__c, __loc); }
96-
#endif
97-
9892
inline _LIBCPP_HIDE_FROM_ABI int __isdigit(int __c, __locale_t __loc) { return ::isdigit_l(__c, __loc); }
9993

10094
inline _LIBCPP_HIDE_FROM_ABI int __isxdigit(int __c, __locale_t __loc) { return ::isxdigit_l(__c, __loc); }

libcxx/include/__locale_dir/support/linux.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,12 +116,6 @@ __strtoull(const char* __nptr, char** __endptr, int __base, __locale_t __loc) {
116116
//
117117
// Character manipulation functions
118118
//
119-
#if defined(_LIBCPP_BUILDING_LIBRARY)
120-
inline _LIBCPP_HIDE_FROM_ABI int __islower(int __c, __locale_t __loc) { return islower_l(__c, __loc); }
121-
122-
inline _LIBCPP_HIDE_FROM_ABI int __isupper(int __c, __locale_t __loc) { return isupper_l(__c, __loc); }
123-
#endif
124-
125119
inline _LIBCPP_HIDE_FROM_ABI int __isdigit(int __c, __locale_t __loc) { return isdigit_l(__c, __loc); }
126120

127121
inline _LIBCPP_HIDE_FROM_ABI int __isxdigit(int __c, __locale_t __loc) { return isxdigit_l(__c, __loc); }

libcxx/include/__locale_dir/support/no_locale/characters.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,6 @@ namespace __locale {
2929
//
3030
// Character manipulation functions
3131
//
32-
#if defined(_LIBCPP_BUILDING_LIBRARY)
33-
inline _LIBCPP_HIDE_FROM_ABI int __islower(int __c, __locale_t) { return std::islower(__c); }
34-
35-
inline _LIBCPP_HIDE_FROM_ABI int __isupper(int __c, __locale_t) { return std::isupper(__c); }
36-
#endif
37-
3832
inline _LIBCPP_HIDE_FROM_ABI int __isdigit(int __c, __locale_t) { return std::isdigit(__c); }
3933

4034
inline _LIBCPP_HIDE_FROM_ABI int __isxdigit(int __c, __locale_t) { return std::isxdigit(__c); }

libcxx/include/__locale_dir/support/windows.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -197,12 +197,6 @@ __strtoull(const char* __nptr, char** __endptr, int __base, __locale_t __loc) {
197197
//
198198
// Character manipulation functions
199199
//
200-
#if defined(_LIBCPP_BUILDING_LIBRARY)
201-
inline _LIBCPP_HIDE_FROM_ABI int __islower(int __c, __locale_t __loc) { return _islower_l(__c, __loc); }
202-
203-
inline _LIBCPP_HIDE_FROM_ABI int __isupper(int __c, __locale_t __loc) { return _isupper_l(__c, __loc); }
204-
#endif
205-
206200
inline _LIBCPP_HIDE_FROM_ABI int __isdigit(int __c, __locale_t __loc) { return _isdigit_l(__c, __loc); }
207201

208202
inline _LIBCPP_HIDE_FROM_ABI int __isxdigit(int __c, __locale_t __loc) { return _isxdigit_l(__c, __loc); }

libcxx/lib/abi/CHANGELOG.TXT

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,15 @@ New entries should be added directly below the "Version" header.
1616
Version 21.0
1717
------------
1818

19+
* [libc++] Optimize ctype::to{lower,upper}
20+
21+
This patch removed __classic_upper_table() and __classic_lower_table(), which were only ever accessed from the dylib.
22+
23+
x86_64-unknown-gnu-linux
24+
------------------------
25+
Symbol removed: _ZNSt3__15ctypeIcE21__classic_lower_tableEv
26+
Symbol removed: _ZNSt3__15ctypeIcE21__classic_upper_tableEv
27+
1928
* [libc++] Instantiate hash function externally
2029

2130
This has multiple benefits:

libcxx/lib/abi/x86_64-unknown-linux-gnu.libcxxabi.v1.stable.exceptions.nonew.abilist

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1318,8 +1318,6 @@
13181318
{'is_defined': True, 'name': '_ZNSt3__15alignEmmRPvRm', 'type': 'FUNC'}
13191319
{'is_defined': True, 'name': '_ZNSt3__15ctypeIcE10table_sizeE', 'size': 8, 'type': 'OBJECT'}
13201320
{'is_defined': True, 'name': '_ZNSt3__15ctypeIcE13classic_tableEv', 'type': 'FUNC'}
1321-
{'is_defined': True, 'name': '_ZNSt3__15ctypeIcE21__classic_lower_tableEv', 'type': 'FUNC'}
1322-
{'is_defined': True, 'name': '_ZNSt3__15ctypeIcE21__classic_upper_tableEv', 'type': 'FUNC'}
13231321
{'is_defined': True, 'name': '_ZNSt3__15ctypeIcE2idE', 'size': 16, 'type': 'OBJECT'}
13241322
{'is_defined': True, 'name': '_ZNSt3__15ctypeIcEC1EPKtbm', 'type': 'FUNC'}
13251323
{'is_defined': True, 'name': '_ZNSt3__15ctypeIcEC2EPKtbm', 'type': 'FUNC'}

0 commit comments

Comments
 (0)