# HG changeset patch
# User Petter Tomner <tomner@kth.se>
# Date 1642107810 -3600
#      Thu Jan 13 22:03:30 2022 +0100
# Node ID 2281499aa31b08bb8feabb7a590e6e4c416ad030
# Parent  f3d3c47e27d334ee926a01c0bb523f21eda5fd8f
WIP: Använd goto och inline ctor i map i scalar

diff -r f3d3c47e27d3 -r 2281499aa31b libinterp/octave-value/ov-scalar.cc
--- a/libinterp/octave-value/ov-scalar.cc	Wed Jan 12 23:46:49 2022 +0100
+++ b/libinterp/octave-value/ov-scalar.cc	Thu Jan 13 22:03:30 2022 +0100
@@ -54,6 +54,7 @@
 #include "xdiv.h"
 #include "xpow.h"
 #include "ops.h"
+#include "ov-inline.h"
 
 #include "ls-oct-text.h"
 #include "ls-hdf5.h"
@@ -369,70 +370,87 @@
   return retval;
 }
 
+static double returns_zero(double) { return 0.; }
+
+static double returns_arg(double d) { return d; }
+
+
 octave_value
 octave_scalar::map (unary_mapper_t umap) const
 {
+  double (*fcn_dbl) (double) = nullptr;
+  Complex (*fcn_cdbl) (double) = nullptr;
+  bool (*fcn_bool) (double) = nullptr;
+
+#define R_SCALAR_MAPPER(UMAP, FCN)                 \
+    case umap_ ## UMAP:                          \
+      fcn_dbl = FCN;                             \
+      goto call_double;
+
+#define C_SCALAR_MAPPER(UMAP, FCN)                \
+    case umap_ ## UMAP:                          \
+      fcn_cdbl = FCN;                            \
+      goto call_complex;
+
+#define B_SCALAR_MAPPER(UMAP, FCN)                \
+    case umap_ ## UMAP:                          \
+      fcn_bool = FCN;                            \
+      goto call_bool;
+
   switch (umap)
     {
-    case umap_imag:
-      return 0.0;
-
-    case umap_real:
-    case umap_conj:
-      return scalar;
-
-#define SCALAR_MAPPER(UMAP, FCN)              \
-    case umap_ ## UMAP:                       \
-      return octave_value (FCN (scalar))
-
-    SCALAR_MAPPER (abs, ::fabs);
-    SCALAR_MAPPER (acos, octave::math::rc_acos);
-    SCALAR_MAPPER (acosh, octave::math::rc_acosh);
-    SCALAR_MAPPER (angle, std::arg);
-    SCALAR_MAPPER (arg, std::arg);
-    SCALAR_MAPPER (asin, octave::math::rc_asin);
-    SCALAR_MAPPER (asinh, octave::math::asinh);
-    SCALAR_MAPPER (atan, ::atan);
-    SCALAR_MAPPER (atanh, octave::math::rc_atanh);
-    SCALAR_MAPPER (erf, octave::math::erf);
-    SCALAR_MAPPER (erfinv, octave::math::erfinv);
-    SCALAR_MAPPER (erfcinv, octave::math::erfcinv);
-    SCALAR_MAPPER (erfc, octave::math::erfc);
-    SCALAR_MAPPER (erfcx, octave::math::erfcx);
-    SCALAR_MAPPER (erfi, octave::math::erfi);
-    SCALAR_MAPPER (dawson, octave::math::dawson);
-    SCALAR_MAPPER (gamma, octave::math::gamma);
-    SCALAR_MAPPER (lgamma, octave::math::rc_lgamma);
-    SCALAR_MAPPER (cbrt, octave::math::cbrt);
-    SCALAR_MAPPER (ceil, ::ceil);
-    SCALAR_MAPPER (cos, ::cos);
-    SCALAR_MAPPER (cosh, ::cosh);
-    SCALAR_MAPPER (exp, ::exp);
-    SCALAR_MAPPER (expm1, octave::math::expm1);
-    SCALAR_MAPPER (fix, octave::math::fix);
-    SCALAR_MAPPER (floor, std::floor);
-    SCALAR_MAPPER (log, octave::math::rc_log);
-    SCALAR_MAPPER (log2, octave::math::rc_log2);
-    SCALAR_MAPPER (log10, octave::math::rc_log10);
-    SCALAR_MAPPER (log1p, octave::math::rc_log1p);
-    SCALAR_MAPPER (round, octave::math::round);
-    SCALAR_MAPPER (roundb, octave::math::roundb);
-    SCALAR_MAPPER (signum, octave::math::signum);
-    SCALAR_MAPPER (sin, ::sin);
-    SCALAR_MAPPER (sinh, ::sinh);
-    SCALAR_MAPPER (sqrt, octave::math::rc_sqrt);
-    SCALAR_MAPPER (tan, ::tan);
-    SCALAR_MAPPER (tanh, ::tanh);
-    SCALAR_MAPPER (isfinite, octave::math::isfinite);
-    SCALAR_MAPPER (isinf, octave::math::isinf);
-    SCALAR_MAPPER (isna, octave::math::isna);
-    SCALAR_MAPPER (isnan, octave::math::isnan);
-    SCALAR_MAPPER (xsignbit, octave::math::signbit);
+    R_SCALAR_MAPPER (imag, returns_zero);
+    R_SCALAR_MAPPER (real, returns_arg);
+    R_SCALAR_MAPPER (conj, returns_arg);
+    R_SCALAR_MAPPER (abs, ::fabs);
+    C_SCALAR_MAPPER (acos, octave::math::rc_acos);
+    C_SCALAR_MAPPER (acosh, octave::math::rc_acosh);
+    R_SCALAR_MAPPER (angle, std::arg);
+    R_SCALAR_MAPPER (arg, std::arg);
+    C_SCALAR_MAPPER (asin, octave::math::rc_asin);
+    R_SCALAR_MAPPER (asinh, octave::math::asinh);
+    R_SCALAR_MAPPER (atan, ::atan);
+    C_SCALAR_MAPPER (atanh, octave::math::rc_atanh);
+    R_SCALAR_MAPPER (erf, octave::math::erf);
+    R_SCALAR_MAPPER (erfinv, octave::math::erfinv);
+    R_SCALAR_MAPPER (erfcinv, octave::math::erfcinv);
+    R_SCALAR_MAPPER (erfc, octave::math::erfc);
+    R_SCALAR_MAPPER (erfcx, octave::math::erfcx);
+    R_SCALAR_MAPPER (erfi, octave::math::erfi);
+    R_SCALAR_MAPPER (dawson, octave::math::dawson);
+    R_SCALAR_MAPPER (gamma, octave::math::gamma);
+    C_SCALAR_MAPPER (lgamma, octave::math::rc_lgamma);
+    R_SCALAR_MAPPER (cbrt, octave::math::cbrt);
+    R_SCALAR_MAPPER (ceil, ::ceil);
+    R_SCALAR_MAPPER (cos, ::cos);
+    R_SCALAR_MAPPER (cosh, ::cosh);
+    R_SCALAR_MAPPER (exp, ::exp);
+    R_SCALAR_MAPPER (expm1, octave::math::expm1);
+    R_SCALAR_MAPPER (fix, octave::math::fix);
+    R_SCALAR_MAPPER (floor, std::floor);
+    C_SCALAR_MAPPER (log, octave::math::rc_log);
+    C_SCALAR_MAPPER (log2, octave::math::rc_log2);
+    C_SCALAR_MAPPER (log10, octave::math::rc_log10);
+    C_SCALAR_MAPPER (log1p, octave::math::rc_log1p);
+    R_SCALAR_MAPPER (round, octave::math::round);
+    R_SCALAR_MAPPER (roundb, octave::math::roundb);
+    R_SCALAR_MAPPER (signum, octave::math::signum);
+    R_SCALAR_MAPPER (sin, ::sin);
+    R_SCALAR_MAPPER (sinh, ::sinh);
+    C_SCALAR_MAPPER (sqrt, octave::math::rc_sqrt);
+    R_SCALAR_MAPPER (tan, ::tan);
+    R_SCALAR_MAPPER (tanh, ::tanh);
+    B_SCALAR_MAPPER (isfinite, octave::math::isfinite);
+    B_SCALAR_MAPPER (isinf, octave::math::isinf);
+    B_SCALAR_MAPPER (isna, octave::math::isna);
+    B_SCALAR_MAPPER (isnan, octave::math::isnan);
+    R_SCALAR_MAPPER (xsignbit, octave::math::signbit);
 
     // Special cases for Matlab compatibility.
     case umap_xtolower:
     case umap_xtoupper:
-      return scalar;
+      fcn_dbl = returns_arg;
+      goto call_double;
 
     case umap_xisalnum:
     case umap_xisalpha:
@@ -446,14 +464,24 @@
     case umap_xisspace:
     case umap_xisupper:
     case umap_xisxdigit:
-      {
-        octave_value str_conv = convert_to_str (true, true);
-        return str_conv.map (umap);
-      }
+      goto return_str;
 
     default:
       return octave_base_value::map (umap);
     }
+
+call_double:
+  return octave_value_factory::make (fcn_dbl (scalar));
+call_complex:
+  return octave_value_factory::make (fcn_cdbl (scalar));
+call_bool:
+  return octave_value_factory::make (fcn_bool (scalar));
+
+return_str:
+  {
+    octave_value str_conv = convert_to_str (true, true);
+    return str_conv.map (umap);
+  }
 }
 
 bool
