Mercurial > octave
changeset 28825:473ee93cf1ea
Replace unwind_protect with more efficient constructs (bug #59192).
* call-stack.cc, input.cc: Replace frame.add_fcn () instances with
unwind_action<> object.
author | Rik <rik@octave.org> |
---|---|
date | Wed, 30 Sep 2020 04:55:19 -0700 |
parents | a98fd0657e35 |
children | e58c51b56d76 |
files | libinterp/corefcn/call-stack.cc libinterp/corefcn/input.cc |
diffstat | 2 files changed, 8 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/corefcn/call-stack.cc Wed Sep 30 04:16:37 2020 -0700 +++ b/libinterp/corefcn/call-stack.cc Wed Sep 30 04:55:19 2020 -0700 @@ -968,14 +968,14 @@ // implement this option there so that the variables are never // stored at all. - unwind_protect frame; - // Set up temporary scope. symbol_scope tmp_scope ("$dummy_scope$"); push (tmp_scope); - frame.add_method (*this, &call_stack::pop); + + octave::unwind_action restore_scope + ([] (auto& self) { self->pop (); }, this); feval ("load", octave_value (file_name), 0);
--- a/libinterp/corefcn/input.cc Wed Sep 30 04:16:37 2020 -0700 +++ b/libinterp/corefcn/input.cc Wed Sep 30 04:55:19 2020 -0700 @@ -926,8 +926,11 @@ "converting from codepage '%s' to UTF-8: %s", encoding.c_str (), std::strerror (errno)); - unwind_protect frame; - frame.add_fcn (::free, static_cast<void *> (utf8_str)); + octave::unwind_action free_utf8_str + ([] (const auto utf8_str_ptr) + { + ::free (utf8_str_ptr); + }, static_cast<void *> (utf8_str)); src_str = std::string (reinterpret_cast<char *> (utf8_str), length); }