summaryrefslogtreecommitdiff
path: root/pp_sort.c
diff options
context:
space:
mode:
authorSalvador FandiƱo <sfandino@yahoo.com>2005-06-06 13:05:05 +0100
committerRafael Garcia-Suarez <rgarciasuarez@gmail.com>2005-06-15 16:16:32 +0000
commit4d56230864c7d2d21814f925d64f6987011e1924 (patch)
tree444be65dce734403284bd379ef09f1c20215fe0a /pp_sort.c
parente54e7e92e82be930d3964d114c29e511355e5ecc (diff)
downloadperl-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.c17
1 files changed, 12 insertions, 5 deletions
diff --git a/pp_sort.c b/pp_sort.c
index b1c62267aa..4b3f56ce73 100644
--- a/pp_sort.c
+++ b/pp_sort.c
@@ -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;
}