changeset 28818:6ec04c206ac4

Replace unwind_protect with more efficient constructs (bug #59192). * dynamic-ld.cc, sparse.cc, __init_gnuplot__.cc: Replace unwind_protect frame and protect_var() call for a simple variable with unwind_protect_var().
author Rik <rik@octave.org>
date Tue, 29 Sep 2020 07:14:05 -0700
parents aef839f40da2
children 52744f8127d7
files libinterp/corefcn/dynamic-ld.cc libinterp/corefcn/sparse.cc libinterp/dldfcn/__init_gnuplot__.cc
diffstat 3 files changed, 4 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/corefcn/dynamic-ld.cc	Tue Sep 29 06:59:13 2020 -0700
+++ b/libinterp/corefcn/dynamic-ld.cc	Tue Sep 29 07:14:05 2020 -0700
@@ -152,11 +152,7 @@
   {
     octave_function *retval = nullptr;
 
-    unwind_protect frame;
-
-    frame.protect_var (m_doing_load);
-
-    m_doing_load = true;
+    octave::unwind_protect_var<bool> restore_var (m_doing_load, true);
 
     dynamic_library oct_file = m_loaded_shlibs.find_file (file_name);
 
@@ -234,11 +230,7 @@
                             const std::string& file_name,
                             bool /*relative*/)
   {
-    unwind_protect frame;
-
-    frame.protect_var (m_doing_load);
-
-    m_doing_load = true;
+    octave::unwind_protect_var<bool> restore_var (m_doing_load, true);
 
     dynamic_library mex_file = m_loaded_shlibs.find_file (file_name);
 
--- a/libinterp/corefcn/sparse.cc	Tue Sep 29 06:59:13 2020 -0700
+++ b/libinterp/corefcn/sparse.cc	Tue Sep 29 07:14:05 2020 -0700
@@ -152,9 +152,7 @@
   octave_value retval;
 
   // Temporarily disable sparse_auto_mutate if set (it's obsolete anyway).
-  octave::unwind_protect frame;
-  frame.protect_var (Vsparse_auto_mutate);
-  Vsparse_auto_mutate = false;
+  octave::unwind_protect_var<bool> restore_var (Vsparse_auto_mutate, false);
 
   if (nargin == 1)
     {
--- a/libinterp/dldfcn/__init_gnuplot__.cc	Tue Sep 29 06:59:13 2020 -0700
+++ b/libinterp/dldfcn/__init_gnuplot__.cc	Tue Sep 29 07:14:05 2020 -0700
@@ -111,10 +111,8 @@
     // Prevent recursion
     if (! drawnow_executing)
       {
-        octave::unwind_protect frame;
-        frame.protect_var (drawnow_executing);
+        octave::unwind_protect_var<bool> restore_var (drawnow_executing, true);
 
-        drawnow_executing = true;
         octave_value_list args;
         args(0) = go.get_handle ().as_octave_value ();
         octave::feval ("__gnuplot_drawnow__", args);