summaryrefslogtreecommitdiff
path: root/pp_sort.c
diff options
context:
space:
mode:
authorSADAHIRO Tomoyuki <BQW10602@nifty.com>2006-07-09 22:47:04 +0900
committerRafael Garcia-Suarez <rgarciasuarez@gmail.com>2006-07-10 10:16:53 +0000
commiteeb9de022215ff745a61968bf9408965f4687655 (patch)
tree7de96e2d3cdbfd82934b652a4966ade3f722f7ac /pp_sort.c
parent46147bce9215db8642f2bdc9a2e9e60e27f046e3 (diff)
downloadperl-eeb9de022215ff745a61968bf9408965f4687655.tar.gz
Add a macro to remove duplicated code
Subject: Re: cut-and-paste findings for blead 28504 Message-Id: <20060709134236.E51A.BQW10602@nifty.com> p4raw-id: //depot/perl@28524
Diffstat (limited to 'pp_sort.c')
-rw-r--r--pp_sort.c34
1 files changed, 10 insertions, 24 deletions
diff --git a/pp_sort.c b/pp_sort.c
index f349c6ff52..0c5f5c1810 100644
--- a/pp_sort.c
+++ b/pp_sort.c
@@ -1847,6 +1847,8 @@ S_sv_i_ncmp(pTHX_ SV *a, SV *b)
? amagic_call(left, right, CAT2(meth,_amg), 0) \
: NULL;
+#define SORT_NORMAL_RETURN_VALUE(val) (((val) > 0) ? 1 : ((val) ? -1 : 0))
+
static I32
S_amagic_ncmp(pTHX_ register SV *a, register SV *b)
{
@@ -1855,15 +1857,11 @@ S_amagic_ncmp(pTHX_ register SV *a, register SV *b)
if (tmpsv) {
if (SvIOK(tmpsv)) {
const I32 i = SvIVX(tmpsv);
- if (i > 0)
- return 1;
- return i? -1 : 0;
+ return SORT_NORMAL_RETURN_VALUE(i);
}
else {
const NV d = SvNV(tmpsv);
- if (d > 0)
- return 1;
- return d ? -1 : 0;
+ return SORT_NORMAL_RETURN_VALUE(d);
}
}
return S_sv_ncmp(aTHX_ a, b);
@@ -1877,15 +1875,11 @@ S_amagic_i_ncmp(pTHX_ register SV *a, register SV *b)
if (tmpsv) {
if (SvIOK(tmpsv)) {
const I32 i = SvIVX(tmpsv);
- if (i > 0)
- return 1;
- return i? -1 : 0;
+ return SORT_NORMAL_RETURN_VALUE(i);
}
else {
const NV d = SvNV(tmpsv);
- if (d > 0)
- return 1;
- return d ? -1 : 0;
+ return SORT_NORMAL_RETURN_VALUE(d);
}
}
return S_sv_i_ncmp(aTHX_ a, b);
@@ -1899,15 +1893,11 @@ S_amagic_cmp(pTHX_ register SV *str1, register SV *str2)
if (tmpsv) {
if (SvIOK(tmpsv)) {
const I32 i = SvIVX(tmpsv);
- if (i > 0)
- return 1;
- return i? -1 : 0;
+ return SORT_NORMAL_RETURN_VALUE(i);
}
else {
const NV d = SvNV(tmpsv);
- if (d > 0)
- return 1;
- return d? -1 : 0;
+ return SORT_NORMAL_RETURN_VALUE(d);
}
}
return sv_cmp(str1, str2);
@@ -1921,15 +1911,11 @@ S_amagic_cmp_locale(pTHX_ register SV *str1, register SV *str2)
if (tmpsv) {
if (SvIOK(tmpsv)) {
const I32 i = SvIVX(tmpsv);
- if (i > 0)
- return 1;
- return i? -1 : 0;
+ return SORT_NORMAL_RETURN_VALUE(i);
}
else {
const NV d = SvNV(tmpsv);
- if (d > 0)
- return 1;
- return d? -1 : 0;
+ return SORT_NORMAL_RETURN_VALUE(d);
}
}
return sv_cmp_locale(str1, str2);