This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Merge the implementations of 10 maths functions in POSIX using ALIAS.
authorNicholas Clark <nick@ccl4.org>
Fri, 9 Sep 2011 10:39:13 +0000 (12:39 +0200)
committerNicholas Clark <nick@ccl4.org>
Tue, 13 Sep 2011 09:28:08 +0000 (11:28 +0200)
10 functions take a single NV argument and return an NV result. Merging them
reduces the shared object size by over 2K on this platform. (Argument
marshalling code in XS is not free.)

ext/POSIX/POSIX.xs

index 8b1a41b..8151d79 100644 (file)
@@ -1252,26 +1252,50 @@ setlocale(category, locale = 0)
 NV
 acos(x)
        NV              x
-
-NV
-asin(x)
-       NV              x
-
-NV
-atan(x)
-       NV              x
-
-NV
-ceil(x)
-       NV              x
-
-NV
-cosh(x)
-       NV              x
-
-NV
-floor(x)
-       NV              x
+    ALIAS:
+       asin = 1
+       atan = 2
+       ceil = 3
+       cosh = 4
+       floor = 5
+       log10 = 6
+       sinh = 7
+       tan = 8
+       tanh = 9
+    CODE:
+       switch (ix) {
+       case 0:
+           RETVAL = acos(x);
+           break;
+       case 1:
+           RETVAL = asin(x);
+           break;
+       case 2:
+           RETVAL = atan(x);
+           break;
+       case 3:
+           RETVAL = ceil(x);
+           break;
+       case 4:
+           RETVAL = cosh(x);
+           break;
+       case 5:
+           RETVAL = floor(x);
+           break;
+       case 6:
+           RETVAL = log10(x);
+           break;
+       case 7:
+           RETVAL = sinh(x);
+           break;
+       case 8:
+           RETVAL = tan(x);
+           break;
+       default:
+           RETVAL = tanh(x);
+       }
+    OUTPUT:
+       RETVAL
 
 NV
 fmod(x,y)
@@ -1292,10 +1316,6 @@ ldexp(x,exp)
        NV              x
        int             exp
 
-NV
-log10(x)
-       NV              x
-
 void
 modf(x)
        NV              x
@@ -1305,18 +1325,6 @@ modf(x)
        PUSHs(sv_2mortal(newSVnv(Perl_modf(x,&intvar))));
        PUSHs(sv_2mortal(newSVnv(intvar)));
 
-NV
-sinh(x)
-       NV              x
-
-NV
-tan(x)
-       NV              x
-
-NV
-tanh(x)
-       NV              x
-
 SysRet
 sigaction(sig, optaction, oldaction = 0)
        int                     sig