[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Octave-bug-tracker] [bug #58105] isfield needs time proportional to num
From: |
anonymous |
Subject: |
[Octave-bug-tracker] [bug #58105] isfield needs time proportional to number of fields |
Date: |
Thu, 9 Apr 2020 14:46:37 -0400 (EDT) |
User-agent: |
Mozilla/5.0 (Windows NT 5.1; rv:60.9) Goanna/4.1 PaleMoon/28.2.0a1 |
Follow-up Comment #1, bug #58105 (project octave):
The "map_value" member of classes "octave_struct" and "octave_scalar_struct"
is very inefficient because it copies all the objects in the container. A fix
would be adding member "isfield" in the classes "octave_value" ,
"octave_base_value" , "octave_struct" and "octave_scalar_struct" that
redirects call to "isfield" member in classes "octave_map" and
"octave_scalar_map" and changing "/libinterp/octave-value/ov-struct.cc
line:1920"
from
octave_map m = args(0).map_value ();
to
const octave_value& m = args(0);
However extensive use of "map_value" in the internal API has the effect of
overall reduction in the performance. A more general fix would be adding
members "map_ref" and "scalar_map_ref" in "octave_value" and the related
classes
const map_ref& () const;
const scalar_map_ref& () const;
Users should be encouraged to use them instead of "map_value" if they need a
read only view to map object.
As a workaround you can define "isfield" as:
function c = isfield (a, b)
try
a.(b);
c = 1;
catch
c = 0;
end
endfunction
Or a more complete workaround:
function c = isfield (a, b)
if b.iscell ()
c = ismember (b, fieldnames (a));
else
try
a.(b);
c = 1;
catch
c = 0;
end
end
end
_______________________________________________________
Reply to this item at:
<https://savannah.gnu.org/bugs/?58105>
_______________________________________________
Message sent via Savannah
https://savannah.gnu.org/