diff options
author | Salvador FandiƱo <sfandino@yahoo.com> | 2005-06-06 13:05:05 +0100 |
---|---|---|
committer | Rafael Garcia-Suarez <rgarciasuarez@gmail.com> | 2005-06-15 16:16:32 +0000 |
commit | 4d56230864c7d2d21814f925d64f6987011e1924 (patch) | |
tree | 444be65dce734403284bd379ef09f1c20215fe0a /pp_sort.c | |
parent | e54e7e92e82be930d3964d114c29e511355e5ecc (diff) | |
download | perl-4d56230864c7d2d21814f925d64f6987011e1924.tar.gz |
sort optimization
Message-ID: <20050606110425.22941.qmail@lists.develooper.com>
p4raw-id: //depot/perl@24853
Diffstat (limited to 'pp_sort.c')
-rw-r--r-- | pp_sort.c | 17 |
1 files changed, 12 insertions, 5 deletions
@@ -1488,6 +1488,10 @@ S_sortsv_desc(pTHX_ SV **array, size_t nmemb, SVCOMPARE_t cmp) sortsvp(aTHX_ array, nmemb, cmp, 1); } +#define SvNSIOK(sv) ((SvFLAGS(sv) & SVf_NOK) || ((SvFLAGS(sv) & (SVf_IOK|SVf_IVisUV)) == SVf_IOK)) +#define SvSIOK(sv) ((SvFLAGS(sv) & (SVf_IOK|SVf_IVisUV)) == SVf_IOK) +#define SvNSIV(sv) ( SvNOK(sv) ? SvNVX(sv) : ( SvSIOK(sv) ? SvIVX(sv) : sv_2nv(sv) ) ) + PP(pp_sort) { dVAR; dSP; dMARK; dORIGMARK; @@ -1507,6 +1511,7 @@ PP(pp_sort) U8 flags = PL_op->op_flags; void (*sortsvp)(pTHX_ SV **array, size_t nmemb, SVCOMPARE_t cmp) = Perl_sortsv; + I32 all_SIVs = 1; if (gimme != G_ARRAY) { SP = MARK; @@ -1609,12 +1614,14 @@ PP(pp_sort) } } else { - if (!SvNOK(*p1)) { + if (!SvNSIOK(*p1)) { if (SvAMAGIC(*p1)) overloading = 1; else (void)sv_2nv(*p1); } + if (all_SIVs && !SvSIOK(*p1)) + all_SIVs = 0; } } else { @@ -1691,9 +1698,9 @@ PP(pp_sort) start = sorting_av ? AvARRAY(av) : ORIGMARK+1; sortsvp(aTHX_ start, max, (priv & OPpSORT_NUMERIC) - ? ( (priv & OPpSORT_INTEGER) + ? ( ( ( priv & OPpSORT_INTEGER) || all_SIVs) ? ( overloading ? amagic_i_ncmp : sv_i_ncmp) - : ( overloading ? amagic_ncmp : sv_ncmp)) + : ( overloading ? amagic_ncmp : sv_ncmp ) ) : ( IN_LOCALE_RUNTIME ? ( overloading ? amagic_cmp_locale @@ -1831,8 +1838,8 @@ sortcv_xsub(pTHX_ SV *a, SV *b) static I32 sv_ncmp(pTHX_ SV *a, SV *b) { - NV nv1 = SvNV(a); - NV nv2 = SvNV(b); + NV nv1 = SvNSIV(a); + NV nv2 = SvNSIV(b); return nv1 < nv2 ? -1 : nv1 > nv2 ? 1 : 0; } |