diff libinterp/octave-value/ov-struct.h @ 31260:c5c8bf50449c

Improve performance of isfield from linear time to constant time (bug #58105) Patch author: Anonymous in Bug #58105 Comment #7 https://savannah.gnu.org/bugs/index.php?58105#comment7 The isfield function was taking time proportional to the number of fields in a struct to determine whether something was a member or not. With this change, isfield performance becomes constant irrespective of the number of fields, speeding up performance by over 200X, and also allowing the use of struct as a hashmap if the user desires. ov-base.h: Add new isfield function declaration ov-base.cc: Add new isfield function definition ov-struct.h: Add new isfield function definitions ov-struct.cc: Do not call map_value ov.h: Add new isfield function definition
author Arun Giridhar <arungiridhar@gmail.com>
date Wed, 05 Oct 2022 10:35:31 -0400
parents 796f54d4ddbf
children 597f3ee61a48
line wrap: on
line diff
--- a/libinterp/octave-value/ov-struct.h	Wed Oct 05 10:55:13 2022 +0200
+++ b/libinterp/octave-value/ov-struct.h	Wed Oct 05 10:35:31 2022 -0400
@@ -130,6 +130,9 @@
 
   string_vector map_keys (void) const { return m_map.fieldnames (); }
 
+  bool isfield (const std::string& field_name) const
+  { return m_map.isfield (field_name); }
+
   void print (std::ostream& os, bool pr_as_read_syntax = false);
 
   void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const;
@@ -256,6 +259,9 @@
 
   string_vector map_keys (void) const { return m_map.fieldnames (); }
 
+  bool isfield (const std::string& field_name) const
+  { return m_map.isfield (field_name); }
+
   void print (std::ostream& os, bool pr_as_read_syntax = false);
 
   void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const;