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;
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;
}
}
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 {
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
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;
}