diff options
author | Tomasz Konojacki <me@xenu.pl> | 2020-03-03 00:45:05 +0100 |
---|---|---|
committer | Karl Williamson <khw@cpan.org> | 2020-03-09 07:55:49 -0600 |
commit | 044d25c73ce10d2b29008b875209d414303ccff7 (patch) | |
tree | 26ad09e5baa999baf53f72a2025f63212943e377 /proto.h | |
parent | 433b3e2b7846f8a9c2506397c0b4d1394bf7700d (diff) | |
download | perl-044d25c73ce10d2b29008b875209d414303ccff7.tar.gz |
optimize sort by inlining comparison functions
This makes special-cased forms such as sort { $b <=> $a }
even faster.
Also, since this commit removes PL_sort_RealCmp, it fixes the
issue with nested sort calls mentioned in gh #16129
Diffstat (limited to 'proto.h')
-rw-r--r-- | proto.h | 99 |
1 files changed, 93 insertions, 6 deletions
@@ -5540,15 +5540,55 @@ STATIC SSize_t S_unpack_rec(pTHX_ struct tempsym* symptr, const char *s, const c assert(symptr); assert(s); assert(strbeg); assert(strend) #endif #if defined(PERL_IN_PP_SORT_C) -STATIC I32 S_amagic_cmp(pTHX_ SV *const str1, SV *const str2); +#ifndef PERL_NO_INLINE_FUNCTIONS +PERL_STATIC_FORCE_INLINE I32 S_amagic_cmp(pTHX_ SV *const str1, SV *const str2) + __attribute__always_inline__; #define PERL_ARGS_ASSERT_AMAGIC_CMP \ assert(str1); assert(str2) -STATIC I32 S_amagic_i_ncmp(pTHX_ SV *const a, SV *const b); +#endif + +#ifndef PERL_NO_INLINE_FUNCTIONS +PERL_STATIC_FORCE_INLINE I32 S_amagic_cmp_desc(pTHX_ SV *const str1, SV *const str2) + __attribute__always_inline__; +#define PERL_ARGS_ASSERT_AMAGIC_CMP_DESC \ + assert(str1); assert(str2) +#endif + +#ifndef PERL_NO_INLINE_FUNCTIONS +PERL_STATIC_FORCE_INLINE I32 S_amagic_i_ncmp(pTHX_ SV *const a, SV *const b) + __attribute__always_inline__; #define PERL_ARGS_ASSERT_AMAGIC_I_NCMP \ assert(a); assert(b) -STATIC I32 S_amagic_ncmp(pTHX_ SV *const a, SV *const b); +#endif + +#ifndef PERL_NO_INLINE_FUNCTIONS +PERL_STATIC_FORCE_INLINE I32 S_amagic_i_ncmp_desc(pTHX_ SV *const a, SV *const b) + __attribute__always_inline__; +#define PERL_ARGS_ASSERT_AMAGIC_I_NCMP_DESC \ + assert(a); assert(b) +#endif + +#ifndef PERL_NO_INLINE_FUNCTIONS +PERL_STATIC_FORCE_INLINE I32 S_amagic_ncmp(pTHX_ SV *const a, SV *const b) + __attribute__always_inline__; #define PERL_ARGS_ASSERT_AMAGIC_NCMP \ assert(a); assert(b) +#endif + +#ifndef PERL_NO_INLINE_FUNCTIONS +PERL_STATIC_FORCE_INLINE I32 S_amagic_ncmp_desc(pTHX_ SV *const a, SV *const b) + __attribute__always_inline__; +#define PERL_ARGS_ASSERT_AMAGIC_NCMP_DESC \ + assert(a); assert(b) +#endif + +#ifndef PERL_NO_INLINE_FUNCTIONS +PERL_STATIC_FORCE_INLINE I32 S_cmp_desc(pTHX_ SV *const str1, SV *const str2) + __attribute__always_inline__; +#define PERL_ARGS_ASSERT_CMP_DESC \ + assert(str1); assert(str2) +#endif + STATIC I32 S_sortcv(pTHX_ SV *const a, SV *const b); #define PERL_ARGS_ASSERT_SORTCV \ assert(a); assert(b) @@ -5558,16 +5598,63 @@ STATIC I32 S_sortcv_stacked(pTHX_ SV *const a, SV *const b); STATIC I32 S_sortcv_xsub(pTHX_ SV *const a, SV *const b); #define PERL_ARGS_ASSERT_SORTCV_XSUB \ assert(a); assert(b) -STATIC I32 S_sv_i_ncmp(pTHX_ SV *const a, SV *const b); +#ifndef PERL_NO_INLINE_FUNCTIONS +PERL_STATIC_FORCE_INLINE void S_sortsv_flags_impl(pTHX_ SV** array, size_t num_elts, SVCOMPARE_t cmp, U32 flags) + __attribute__always_inline__; +#define PERL_ARGS_ASSERT_SORTSV_FLAGS_IMPL \ + assert(cmp) +#endif + +#ifndef PERL_NO_INLINE_FUNCTIONS +PERL_STATIC_FORCE_INLINE I32 S_sv_i_ncmp(pTHX_ SV *const a, SV *const b) + __attribute__always_inline__; #define PERL_ARGS_ASSERT_SV_I_NCMP \ assert(a); assert(b) -STATIC I32 S_sv_ncmp(pTHX_ SV *const a, SV *const b); +#endif + +#ifndef PERL_NO_INLINE_FUNCTIONS +PERL_STATIC_FORCE_INLINE I32 S_sv_i_ncmp_desc(pTHX_ SV *const a, SV *const b) + __attribute__always_inline__; +#define PERL_ARGS_ASSERT_SV_I_NCMP_DESC \ + assert(a); assert(b) +#endif + +#ifndef PERL_NO_INLINE_FUNCTIONS +PERL_STATIC_FORCE_INLINE I32 S_sv_ncmp(pTHX_ SV *const a, SV *const b) + __attribute__always_inline__; #define PERL_ARGS_ASSERT_SV_NCMP \ assert(a); assert(b) +#endif + +#ifndef PERL_NO_INLINE_FUNCTIONS +PERL_STATIC_FORCE_INLINE I32 S_sv_ncmp_desc(pTHX_ SV *const a, SV *const b) + __attribute__always_inline__; +#define PERL_ARGS_ASSERT_SV_NCMP_DESC \ + assert(a); assert(b) +#endif + # if defined(USE_LOCALE_COLLATE) -STATIC I32 S_amagic_cmp_locale(pTHX_ SV *const str1, SV *const str2); +#ifndef PERL_NO_INLINE_FUNCTIONS +PERL_STATIC_FORCE_INLINE I32 S_amagic_cmp_locale(pTHX_ SV *const str1, SV *const str2) + __attribute__always_inline__; #define PERL_ARGS_ASSERT_AMAGIC_CMP_LOCALE \ assert(str1); assert(str2) +#endif + +#ifndef PERL_NO_INLINE_FUNCTIONS +PERL_STATIC_FORCE_INLINE I32 S_amagic_cmp_locale_desc(pTHX_ SV *const str1, SV *const str2) + __attribute__always_inline__; +#define PERL_ARGS_ASSERT_AMAGIC_CMP_LOCALE_DESC \ + assert(str1); assert(str2) +#endif + +#ifndef PERL_NO_INLINE_FUNCTIONS +PERL_STATIC_FORCE_INLINE I32 S_cmp_locale_desc(pTHX_ SV *const str1, SV *const str2) + __attribute__always_inline__; +#define PERL_ARGS_ASSERT_CMP_LOCALE_DESC \ + assert(str1); assert(str2) +#endif + # endif #endif #if defined(PERL_IN_PP_SYS_C) |