Inkscape
Vector Graphics Editor
|
A FuncLog is effectively a std::vector<std::function<void()>>, with the ability to hold move-only function types and enforced run-once semantics. More...
#include <funclog.h>
Classes | |
struct | Entry |
struct | Header |
Public Member Functions | |
FuncLog ()=default | |
FuncLog (FuncLog &&other) noexcept | |
FuncLog & | operator= (FuncLog &&other) noexcept |
~FuncLog () | |
template<typename F > | |
void | emplace (F &&f) |
Append a callable object to the log. | |
void | exec () |
Execute and destroy each callable in the log. | |
void | operator() () |
Convenience alias for exec(). | |
template<typename C > | |
void | exec_while (C &&c) |
Execute and destroy each callable in the log while condition c() is true, then destroy the rest. | |
void | clear () |
Destroy all callables in the log without executing them. | |
bool | empty () const |
Private Member Functions | |
void | destroy () |
void | reset () noexcept |
void | movefrom (FuncLog &other) noexcept |
Static Private Member Functions | |
static void | destroy_from (Header *h) |
static void | destroy_and_advance (Header *&h) noexcept |
Private Attributes | |
Pool | pool |
Header * | first = nullptr |
Header ** | lastnext = &first |
A FuncLog is effectively a std::vector<std::function<void()>>, with the ability to hold move-only function types and enforced run-once semantics.
The main difference is an efficient internal representation that stores the contents nearly contiguously. This gives a 2x speedup when std::function uses the small-lambda optimisation, and a 7x speedup when it has to heap-allocate.
|
default |
|
inlinenoexcept |
Definition at line 27 of file funclog.h.
References movefrom().
|
inline |
|
inline |
|
inlineprivate |
Definition at line 109 of file funclog.h.
References destroy_from(), and first.
Referenced by clear(), operator=(), and ~FuncLog().
|
staticprivatenoexcept |
Definition at line 21 of file funclog.cpp.
Referenced by destroy_from(), exec(), and exec_while().
|
inlinestaticprivate |
Definition at line 110 of file funclog.h.
References destroy_and_advance().
Referenced by destroy(), exec(), and exec_while().
|
inline |
Append a callable object to the log.
On exception, no object is inserted, though memory will not be returned immediately.
Definition at line 36 of file funclog.h.
References Inkscape::Util::Pool::allocate(), lastnext, Inkscape::Util::FuncLog::Header::next, and pool.
Referenced by Inkscape::CanvasItemContext::defer(), Inkscape::Drawing::defer(), and Inkscape::Async::Channel::detail::Shared::run().
|
inline |
Definition at line 86 of file funclog.h.
References first.
Referenced by Inkscape::Async::Channel::detail::Shared::run().
void Inkscape::Util::FuncLog::exec | ( | ) |
Execute and destroy each callable in the log.
On exception, all remaining callables are destroyed.
Definition at line 7 of file funclog.cpp.
References destroy_and_advance(), destroy_from(), first, and reset().
Referenced by operator()().
|
inline |
Execute and destroy each callable in the log while condition c() is true, then destroy the rest.
On exception, all remaining callables are destroyed.
Definition at line 62 of file funclog.h.
References c, destroy_and_advance(), destroy_from(), first, and reset().
Referenced by Inkscape::Async::Channel::detail::Shared::Shared().
|
privatenoexcept |
Definition at line 35 of file funclog.cpp.
Referenced by FuncLog(), and operator=().
|
inline |
Definition at line 28 of file funclog.h.
References destroy(), and movefrom().
|
privatenoexcept |
Definition at line 28 of file funclog.cpp.
References first, Inkscape::Util::Pool::free_all(), lastnext, and pool.
Referenced by clear(), exec(), and exec_while().
|
private |
|
private |