Mercurial > octave
view libinterp/octave-value/cdef-utils.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 | e88a07dec498 |
line wrap: on
line source
//////////////////////////////////////////////////////////////////////// // // Copyright (C) 2012-2022 The Octave Project Developers // // See the file COPYRIGHT.md in the top-level directory of this // distribution or <https://octave.org/copyright/>. // // This file is part of Octave. // // Octave is free software: you can redistribute it and/or modify it // under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // Octave is distributed in the hope that it will be useful, but // WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with Octave; see the file COPYING. If not, see // <https://www.gnu.org/licenses/>. // //////////////////////////////////////////////////////////////////////// #if ! defined (octave_cdef_utils_h) #define octave_cdef_utils_h 1 #include "octave-config.h" #include <list> #include <string> #include "cdef-fwd.h" class octave_value; class Cell; namespace octave { extern OCTINTERP_API std::string get_base_name (const std::string& nm); extern OCTINTERP_API void make_function_of_class (const std::string& class_name, const octave_value& fcn); extern OCTINTERP_API void make_function_of_class (const cdef_class& cls, const octave_value& fcn); extern OCTINTERP_API cdef_class lookup_class (const std::string& name, bool error_if_not_found = true, bool load_if_not_found = true); extern OCTINTERP_API cdef_class lookup_class (const cdef_class& cls); extern OCTINTERP_API cdef_class lookup_class (const octave_value& ov); extern OCTINTERP_API std::list<cdef_class> lookup_classes (const Cell& cls_list); extern OCTINTERP_API octave_value to_ov (const cdef_object& obj); extern OCTINTERP_API octave_value to_ov (const octave_value& ov); extern OCTINTERP_API cdef_object to_cdef (const octave_value& val); extern OCTINTERP_API cdef_object& to_cdef_ref (const octave_value& val); extern OCTINTERP_API cdef_object to_cdef (const cdef_object& obj); extern OCTINTERP_API octave_value to_ov (const std::list<cdef_class>& class_list); extern OCTINTERP_API bool is_dummy_method (const octave_value& fcn); extern OCTINTERP_API bool is_superclass (const cdef_class& clsa, const cdef_class& clsb, bool allow_equal = true, int max_depth = -1); extern OCTINTERP_API bool is_strict_superclass (const cdef_class& clsa, const cdef_class& clsb); extern OCTINTERP_API bool is_direct_superclass (const cdef_class& clsa, const cdef_class& clsb); extern OCTINTERP_API cdef_package lookup_package (const std::string& name, bool error_if_not_found = true, bool load_if_not_found = true); extern OCTINTERP_API cdef_class get_class_context (std::string& name, bool& in_constructor); extern OCTINTERP_API cdef_class get_class_context (void); extern OCTINTERP_API bool check_access (const cdef_class& cls, const octave_value& acc, const std::string& meth_name = "", const std::string& prop_name = "", bool is_prop_set = false); } #endif