changeset 28625:173807014259

jsondecode.cc: Prefer STL to custom comparison function * libinterp/corefcn/jsondecode.cc (equals): Remove function. * libinterp/corefcn/jsondecode.cc (decode_object_array): Prefer STL to custom comparison function. `string_vector::std_list()` allows conversion to STL data type and one can make use of STL comparision functions. See https://en.cppreference.com/w/cpp/container/list/operator_cmp
author Kai T. Ohlhus <k.ohlhus@gmail.com>
date Tue, 18 Aug 2020 15:22:48 +0900
parents aae9d7f098bd
children 34696240591e
files libinterp/corefcn/jsondecode.cc
diffstat 1 files changed, 3 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/corefcn/jsondecode.cc	Tue Aug 18 14:44:22 2020 +0900
+++ b/libinterp/corefcn/jsondecode.cc	Tue Aug 18 15:22:48 2020 +0900
@@ -43,35 +43,6 @@
 octave_value
 decode (const rapidjson::Value& val, const octave_value_list& options);
 
-//! Checks if two instances of @ref string_vector are equal.
-//!
-//! @param a The first @ref string_vector.
-//! @param b The second @ref string_vector.
-//!
-//! @return @c bool that indicates if they are equal.
-//!
-//! @b Example:
-//!
-//! @code{.cc}
-//! string_vector a ({"foo", "bar"});
-//! string_vector b ({"foo", "baz"});
-//! bool is_equal = equals (a, b);
-//! @endcode
-
-bool
-equals (const string_vector& a, const string_vector& b)
-{
-  // FIXME: move to string_vector class
-  octave_idx_type n = a.numel ();
-  if (n != b.numel ())
-    return false;
-  for (octave_idx_type i = 0; i < n; ++i)
-    if (a(i) != b(i))
-      return false;
-
-  return true;
-}
-
 //! Decodes a numerical JSON value into a scalar number.
 //!
 //! @param val JSON value that is guaranteed to be a numerical value.
@@ -249,9 +220,10 @@
 {
   Cell struct_cell = decode_string_and_mixed_array (val, options).cell_value ();
   string_vector field_names = struct_cell(0).scalar_map_value ().fieldnames ();
-  bool same_field_names = 1;
+  bool same_field_names = true;
   for (octave_idx_type i = 1; i < struct_cell.numel (); ++i)
-    if (! equals (field_names, struct_cell(i).scalar_map_value ().fieldnames ()))
+    if (field_names.std_list ()
+        != struct_cell(i).scalar_map_value ().fieldnames ().std_list ())
       {
         same_field_names = 0;
         break;