changeset 20530:bf6c4433ed5f

Clean up isa() function. * ov-class.cc (Fisa): Remove not strictly necessary const modifiers on variables. Use more meaningful variable names. Put direct test for class name first in if tree since this is the most likely test to succeed.
author Rik <rik@octave.org>
date Tue, 22 Sep 2015 01:38:40 -0700
parents fbbdd14aa7ce
children bb09279e5c99
files libinterp/octave-value/ov-class.cc
diffstat 1 files changed, 11 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/octave-value/ov-class.cc	Mon Sep 21 17:56:03 2015 +0200
+++ b/libinterp/octave-value/ov-class.cc	Tue Sep 22 01:38:40 2015 -0700
@@ -1985,23 +1985,24 @@
       return retval;
     }
 
-  octave_value obj = args(0); // not const because of find_parent_class ()
-  const Array<std::string> cls = args(1).cellstr_value ();
+  octave_value obj = args(0);  // not const because of find_parent_class ()
+  std::string obj_cls = obj.class_name ();
+  Array<std::string> clsnames = args(1).cellstr_value ();
   if (error_state)
     {
       error ("isa: CLASSNAME must be a string or cell array of strings");
       return retval;
     }
 
-  boolNDArray matches (cls.dims (), false);
-  const octave_idx_type n = cls.numel ();
-  for (octave_idx_type idx = 0; idx < n; idx++)
+  boolNDArray matches (clsnames.dims (), false);
+  for (octave_idx_type idx = 0; idx < clsnames.numel (); idx++)
     {
-      const std::string cl = cls(idx);
-      if ((cl == "float"   && obj.is_float_type   ())
-          || (cl == "integer" && obj.is_integer_type ())
-          || (cl == "numeric" && obj.is_numeric_type ())
-          || obj.class_name () == cl || obj.is_instance_of (cl))
+      std::string cls = clsnames(idx);
+      if (obj_cls == cls
+          || (cls == "float"   && obj.is_float_type   ())
+          || (cls == "integer" && obj.is_integer_type ())
+          || (cls == "numeric" && obj.is_numeric_type ())
+          || obj.is_instance_of (cls))
         matches(idx) = true;
     }
   return octave_value (matches);