mirror of
https://github.com/KjellKod/g3log.git
synced 2024-12-12 18:30:25 +01:00
performance increase by using internal unique_ptr for the sink instead of shared_pointer.
Better average (10-15%), and much, much, much better worst case
This commit is contained in:
parent
d0045de73b
commit
63616d2acd
@ -65,8 +65,7 @@ public:
|
||||
std::unique_ptr<g2::SinkHandle<T >> addSink(std::unique_ptr<T> real_sink, DefaultLogCall call) {
|
||||
using namespace g2;
|
||||
using namespace g2::internal;
|
||||
auto shared_sink = std::shared_ptr<T>(real_sink.release());
|
||||
auto sink = std::make_shared < Sink < T >> (shared_sink, call);
|
||||
auto sink = std::make_shared < Sink < T >> (std::move(real_sink), call);
|
||||
addWrappedSink(sink);
|
||||
return std2::make_unique < SinkHandle < T >> (sink);
|
||||
}
|
||||
|
@ -33,21 +33,21 @@ typedef std::function<void(LogMessageMover) > AsyncMessageCall;
|
||||
|
||||
template<class T>
|
||||
struct Sink : public SinkWrapper {
|
||||
std::shared_ptr<T> _real_sink;
|
||||
std::unique_ptr<T> _real_sink;
|
||||
std::unique_ptr<kjellkod::Active> _bg;
|
||||
AsyncMessageCall _default_log_call;
|
||||
|
||||
template<typename DefaultLogCall >
|
||||
Sink(std::shared_ptr<T> sink, DefaultLogCall call)
|
||||
Sink(std::unique_ptr<T> sink, DefaultLogCall call)
|
||||
: SinkWrapper (),
|
||||
_real_sink{sink},
|
||||
_real_sink{std::move(sink)},
|
||||
_bg(kjellkod::Active::createActive()),
|
||||
_default_log_call(std::bind(call, _real_sink.get(), std::placeholders::_1)) {
|
||||
}
|
||||
|
||||
Sink(std::shared_ptr<T> sink, void(T::*Call)(std::string) )
|
||||
Sink(std::unique_ptr<T> sink, void(T::*Call)(std::string) )
|
||||
: SinkWrapper(),
|
||||
_real_sink {sink},
|
||||
_real_sink {std::move(sink)},
|
||||
_bg(kjellkod::Active::createActive()) {
|
||||
auto adapter = std::bind(Call, _real_sink.get(), std::placeholders::_1);
|
||||
_default_log_call = [ = ](LogMessageMover m){adapter(m.get().toString());};
|
||||
|
@ -85,10 +85,8 @@ namespace g2 {
|
||||
|
||||
template<typename T, typename DefaultLogCall>
|
||||
std::unique_ptr< SinkHandle<T> > addSink(std::unique_ptr<T> unique, DefaultLogCall call) {
|
||||
auto shared = std::shared_ptr<T>(unique.release());
|
||||
auto sink = std::make_shared < internal::Sink<T> > (shared, call);
|
||||
auto sink = std::make_shared < internal::Sink<T> > (std::move(unique), call);
|
||||
auto add_sink_call = [this, sink] { _container.push_back(sink); };
|
||||
|
||||
auto wait_result = g2::spawn_task(add_sink_call, _bg.get());
|
||||
wait_result.wait();
|
||||
|
||||
@ -101,6 +99,7 @@ namespace g2 {
|
||||
|
||||
|
||||
|
||||
|
||||
using namespace g2;
|
||||
using namespace g2::internal;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user