Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
Inkscape::Util::FuncLog Class Referencefinal

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
 
FuncLogoperator= (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
 
Headerfirst = nullptr
 
Header ** lastnext = &first
 

Detailed Description

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.

Definition at line 23 of file funclog.h.

Constructor & Destructor Documentation

◆ FuncLog() [1/2]

Inkscape::Util::FuncLog::FuncLog ( )
default

◆ FuncLog() [2/2]

Inkscape::Util::FuncLog::FuncLog ( FuncLog &&  other)
inlinenoexcept

Definition at line 27 of file funclog.h.

References movefrom().

◆ ~FuncLog()

Inkscape::Util::FuncLog::~FuncLog ( )
inline

Definition at line 29 of file funclog.h.

References destroy().

Member Function Documentation

◆ clear()

void Inkscape::Util::FuncLog::clear ( )
inline

Destroy all callables in the log without executing them.

Postcondition
empty() == true

Definition at line 84 of file funclog.h.

References destroy(), and reset().

Referenced by Inkscape::Async::Channel::detail::Shared::close().

◆ destroy()

void Inkscape::Util::FuncLog::destroy ( )
inlineprivate

Definition at line 109 of file funclog.h.

References destroy_from(), and first.

Referenced by clear(), operator=(), and ~FuncLog().

◆ destroy_and_advance()

void Inkscape::Util::FuncLog::destroy_and_advance ( Header *&  h)
staticprivatenoexcept

Definition at line 21 of file funclog.cpp.

Referenced by destroy_from(), exec(), and exec_while().

◆ destroy_from()

static void Inkscape::Util::FuncLog::destroy_from ( Header h)
inlinestaticprivate

Definition at line 110 of file funclog.h.

References destroy_and_advance().

Referenced by destroy(), exec(), and exec_while().

◆ emplace()

template<typename F >
void Inkscape::Util::FuncLog::emplace ( F &&  f)
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().

◆ empty()

bool Inkscape::Util::FuncLog::empty ( ) const
inline

Definition at line 86 of file funclog.h.

References first.

Referenced by Inkscape::Async::Channel::detail::Shared::run().

◆ exec()

void Inkscape::Util::FuncLog::exec ( )

Execute and destroy each callable in the log.

On exception, all remaining callables are destroyed.

Postcondition
empty() == true

Definition at line 7 of file funclog.cpp.

References destroy_and_advance(), destroy_from(), first, and reset().

Referenced by operator()().

◆ exec_while()

template<typename C >
void Inkscape::Util::FuncLog::exec_while ( C &&  c)
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.

Postcondition
empty() == true

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().

◆ movefrom()

void Inkscape::Util::FuncLog::movefrom ( FuncLog other)
privatenoexcept

Definition at line 35 of file funclog.cpp.

Referenced by FuncLog(), and operator=().

◆ operator()()

void Inkscape::Util::FuncLog::operator() ( )
inline

Convenience alias for exec().

Definition at line 54 of file funclog.h.

References exec().

◆ operator=()

FuncLog & Inkscape::Util::FuncLog::operator= ( FuncLog &&  other)
inlinenoexcept

Definition at line 28 of file funclog.h.

References destroy(), and movefrom().

◆ reset()

void Inkscape::Util::FuncLog::reset ( )
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().

Member Data Documentation

◆ first

Header* Inkscape::Util::FuncLog::first = nullptr
private

Definition at line 106 of file funclog.h.

Referenced by destroy(), empty(), exec(), exec_while(), and reset().

◆ lastnext

Header** Inkscape::Util::FuncLog::lastnext = &first
private

Definition at line 107 of file funclog.h.

Referenced by emplace(), and reset().

◆ pool

Pool Inkscape::Util::FuncLog::pool
private

Definition at line 105 of file funclog.h.

Referenced by emplace(), and reset().


The documentation for this class was generated from the following files: