@@ -210,25 +210,22 @@ struct _LIBCPP_TEMPLATE_VIS char_traits<char>
210210 static inline _LIBCPP_CONSTEXPR bool lt (char_type __c1, char_type __c2) _NOEXCEPT
211211 {return (unsigned char )__c1 < (unsigned char )__c2;}
212212
213- static _LIBCPP_CONSTEXPR_SINCE_CXX17
214- int compare (const char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT;
213+ static _LIBCPP_CONSTEXPR_SINCE_CXX17 int compare (const char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT {
214+ if (__n == 0 )
215+ return 0 ;
216+ return std::__constexpr_memcmp (__s1, __s2, __n);
217+ }
215218
216- static inline size_t _LIBCPP_CONSTEXPR_SINCE_CXX17 length (const char_type* __s) _NOEXCEPT {
217- // GCC currently does not support __builtin_strlen during constant evaluation.
218- // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70816
219- #ifdef _LIBCPP_COMPILER_GCC
220- if (__libcpp_is_constant_evaluated ()) {
221- size_t __i = 0 ;
222- for (; __s[__i] != char_type (' \0 ' ); ++__i)
223- ;
224- return __i;
225- }
226- #endif
227- return __builtin_strlen (__s);
228- }
219+ static inline size_t _LIBCPP_CONSTEXPR_SINCE_CXX17 length (const char_type* __s) _NOEXCEPT {
220+ return std::__constexpr_strlen (__s);
221+ }
229222
230- static _LIBCPP_CONSTEXPR_SINCE_CXX17
231- const char_type* find (const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT;
223+ static _LIBCPP_CONSTEXPR_SINCE_CXX17
224+ const char_type* find (const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT {
225+ if (__n == 0 )
226+ return nullptr ;
227+ return std::__constexpr_char_memchr (__s, static_cast <int >(__a), __n);
228+ }
232229
233230 static inline _LIBCPP_CONSTEXPR_SINCE_CXX20
234231 char_type* move (char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT {
@@ -261,49 +258,6 @@ struct _LIBCPP_TEMPLATE_VIS char_traits<char>
261258 {return int_type (EOF);}
262259};
263260
264- inline _LIBCPP_CONSTEXPR_SINCE_CXX17
265- int
266- char_traits<char >::compare(const char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT
267- {
268- if (__n == 0 )
269- return 0 ;
270- #if __has_feature(cxx_constexpr_string_builtins)
271- return __builtin_memcmp (__s1, __s2, __n);
272- #elif _LIBCPP_STD_VER <= 14
273- return _VSTD::memcmp (__s1, __s2, __n);
274- #else
275- for (; __n; --__n, ++__s1, ++__s2)
276- {
277- if (lt (*__s1, *__s2))
278- return -1 ;
279- if (lt (*__s2, *__s1))
280- return 1 ;
281- }
282- return 0 ;
283- #endif
284- }
285-
286- inline _LIBCPP_CONSTEXPR_SINCE_CXX17
287- const char *
288- char_traits<char >::find(const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT
289- {
290- if (__n == 0 )
291- return nullptr ;
292- #if __has_feature(cxx_constexpr_string_builtins)
293- return __builtin_char_memchr (__s, to_int_type (__a), __n);
294- #elif _LIBCPP_STD_VER <= 14
295- return (const char_type*) _VSTD::memchr (__s, to_int_type (__a), __n);
296- #else
297- for (; __n; --__n)
298- {
299- if (eq (*__s, __a))
300- return __s;
301- ++__s;
302- }
303- return nullptr ;
304- #endif
305- }
306-
307261// char_traits<wchar_t>
308262
309263#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
@@ -326,12 +280,22 @@ struct _LIBCPP_TEMPLATE_VIS char_traits<wchar_t>
326280 static inline _LIBCPP_CONSTEXPR bool lt (char_type __c1, char_type __c2) _NOEXCEPT
327281 {return __c1 < __c2;}
328282
329- static _LIBCPP_CONSTEXPR_SINCE_CXX17
330- int compare (const char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT;
331- static _LIBCPP_CONSTEXPR_SINCE_CXX17
332- size_t length (const char_type* __s) _NOEXCEPT;
333- static _LIBCPP_CONSTEXPR_SINCE_CXX17
334- const char_type* find (const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT;
283+ static _LIBCPP_CONSTEXPR_SINCE_CXX17 int compare (const char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT {
284+ if (__n == 0 )
285+ return 0 ;
286+ return std::__constexpr_wmemcmp (__s1, __s2, __n);
287+ }
288+
289+ static _LIBCPP_CONSTEXPR_SINCE_CXX17 size_t length (const char_type* __s) _NOEXCEPT {
290+ return std::__constexpr_wcslen (__s);
291+ }
292+
293+ static _LIBCPP_CONSTEXPR_SINCE_CXX17
294+ const char_type* find (const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT {
295+ if (__n == 0 )
296+ return nullptr ;
297+ return std::__constexpr_wmemchr (__s, __a, __n);
298+ }
335299
336300 static inline _LIBCPP_CONSTEXPR_SINCE_CXX20
337301 char_type* move (char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT {
@@ -363,65 +327,6 @@ struct _LIBCPP_TEMPLATE_VIS char_traits<wchar_t>
363327 static inline _LIBCPP_CONSTEXPR int_type eof () _NOEXCEPT
364328 {return int_type (WEOF);}
365329};
366-
367- inline _LIBCPP_CONSTEXPR_SINCE_CXX17
368- int
369- char_traits<wchar_t >::compare(const char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT
370- {
371- if (__n == 0 )
372- return 0 ;
373- #if __has_feature(cxx_constexpr_string_builtins)
374- return __builtin_wmemcmp (__s1, __s2, __n);
375- #elif _LIBCPP_STD_VER <= 14
376- return _VSTD::wmemcmp (__s1, __s2, __n);
377- #else
378- for (; __n; --__n, ++__s1, ++__s2)
379- {
380- if (lt (*__s1, *__s2))
381- return -1 ;
382- if (lt (*__s2, *__s1))
383- return 1 ;
384- }
385- return 0 ;
386- #endif
387- }
388-
389- inline _LIBCPP_CONSTEXPR_SINCE_CXX17
390- size_t
391- char_traits<wchar_t >::length(const char_type* __s) _NOEXCEPT
392- {
393- #if __has_feature(cxx_constexpr_string_builtins)
394- return __builtin_wcslen (__s);
395- #elif _LIBCPP_STD_VER <= 14
396- return _VSTD::wcslen (__s);
397- #else
398- size_t __len = 0 ;
399- for (; !eq (*__s, char_type (0 )); ++__s)
400- ++__len;
401- return __len;
402- #endif
403- }
404-
405- inline _LIBCPP_CONSTEXPR_SINCE_CXX17
406- const wchar_t *
407- char_traits<wchar_t >::find(const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT
408- {
409- if (__n == 0 )
410- return nullptr ;
411- #if __has_feature(cxx_constexpr_string_builtins)
412- return __builtin_wmemchr (__s, __a, __n);
413- #elif _LIBCPP_STD_VER <= 14
414- return _VSTD::wmemchr (__s, __a, __n);
415- #else
416- for (; __n; --__n)
417- {
418- if (eq (*__s, __a))
419- return __s;
420- ++__s;
421- }
422- return nullptr ;
423- #endif
424- }
425330#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
426331
427332#ifndef _LIBCPP_HAS_NO_CHAR8_T
@@ -445,8 +350,10 @@ struct _LIBCPP_TEMPLATE_VIS char_traits<char8_t>
445350 static inline constexpr bool lt (char_type __c1, char_type __c2) noexcept
446351 {return __c1 < __c2;}
447352
448- static constexpr
449- int compare (const char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT;
353+ static _LIBCPP_HIDE_FROM_ABI constexpr int
354+ compare (const char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT {
355+ return std::__constexpr_memcmp (__s1, __s2, __n);
356+ }
450357
451358 static constexpr
452359 size_t length (const char_type* __s) _NOEXCEPT;
@@ -496,24 +403,6 @@ char_traits<char8_t>::length(const char_type* __s) _NOEXCEPT
496403 return __len;
497404}
498405
499- inline constexpr
500- int
501- char_traits<char8_t >::compare(const char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT
502- {
503- #if __has_feature(cxx_constexpr_string_builtins)
504- return __builtin_memcmp (__s1, __s2, __n);
505- #else
506- for (; __n; --__n, ++__s1, ++__s2)
507- {
508- if (lt (*__s1, *__s2))
509- return -1 ;
510- if (lt (*__s2, *__s1))
511- return 1 ;
512- }
513- return 0 ;
514- #endif
515- }
516-
517406// TODO use '__builtin_char_memchr' if it ever supports char8_t ??
518407inline constexpr
519408const char8_t *
0 commit comments