This patch was generated using clang-tidy:
clang-tidy -checks="-*,modernize-make-shared" -fix
(with some additional manual fixups)
Using make_shared() over manual construction has multiple advantages:
- It's shorter to write and easier to read.
V1: auto sb = shared_ptr<Foo>(new Foo());
V2: auto sb = make_shared<Foo>();
- The type "Foo" is repeated less often (less code duplication, lower
risk of forgetting to update one of the "Foo"s upon copy-paste etc.)
- Manual construction leads to two individual allocations (actual data and
the control block of the shared_ptr). Using make_shared() will only lead
to one allocation, which has performance, cache-locality and memory
consumption benefits.
- It's exception-safe, whereas manual construction is not necessarily:
V1: func(shared_ptr<Foo>(new Foo()), shared_ptr<Foo>(new Foo()));
V2: func(make_shared<Foo>(), make_shared<Foo>());
In "V1", one of the "new" invocations could throw, potentially
causing memory leaks. No leaks will happen with make_shared().
using std::map;
using std::pair;
using std::shared_ptr;
using std::map;
using std::pair;
using std::shared_ptr;
using std::vector;
using namespace pv::data::decode;
using std::vector;
using namespace pv::data::decode;
connect(&session_, SIGNAL(frame_ended()),
this, SLOT(on_frame_ended()));
connect(&session_, SIGNAL(frame_ended()),
this, SLOT(on_frame_ended()));
- stack_.push_back(shared_ptr<decode::Decoder>(
- new decode::Decoder(dec)));
+ stack_.push_back(make_shared<decode::Decoder>(dec));
}
DecoderStack::~DecoderStack()
}
DecoderStack::~DecoderStack()
using std::mutex;
using std::set;
using std::shared_ptr;
using std::mutex;
using std::set;
using std::shared_ptr;
using std::unordered_set;
using std::vector;
using std::unordered_set;
using std::vector;
// popup.
shared_ptr<Device> binding;
if (group)
// popup.
shared_ptr<Device> binding;
if (group)
- binding = shared_ptr<Device>(new Device(group));
+ binding = make_shared<Device>(group);
// Create a title if the group is going to have any content
if ((!sigs.empty() || (binding && !binding->properties().empty())) &&
// Create a title if the group is going to have any content
if ((!sigs.empty() || (binding && !binding->properties().empty())) &&
using std::recursive_mutex;
using std::set;
using std::shared_ptr;
using std::recursive_mutex;
using std::set;
using std::shared_ptr;
using std::string;
using std::unordered_set;
using std::vector;
using std::string;
using std::unordered_set;
using std::vector;
settings.endGroup();
if (QFileInfo(filename).isReadable()) {
settings.endGroup();
if (QFileInfo(filename).isReadable()) {
- device = std::make_shared<devices::SessionFile>(device_manager_.context(),
+ device = make_shared<devices::SessionFile>(device_manager_.context(),
filename.toStdString());
set_device(device);
filename.toStdString());
set_device(device);
try {
// Create the decoder
try {
// Create the decoder
- decoder_stack = shared_ptr<data::DecoderStack>(
- new data::DecoderStack(*this, dec));
+ decoder_stack = make_shared<data::DecoderStack>(*this, dec);
// Make a list of all the channels
std::vector<const srd_channel*> all_channels;
// Make a list of all the channels
std::vector<const srd_channel*> all_channels;
// Create the decode signal
shared_ptr<data::SignalBase> signalbase =
// Create the decode signal
shared_ptr<data::SignalBase> signalbase =
- shared_ptr<data::SignalBase>(new data::SignalBase(nullptr));
+ make_shared<data::SignalBase>(nullptr);
signalbase->set_decoder_stack(decoder_stack);
signalbases_.insert(signalbase);
signalbase->set_decoder_stack(decoder_stack);
signalbases_.insert(signalbase);
switch(channel->type()->id()) {
case SR_CHANNEL_LOGIC:
if (!signalbase) {
switch(channel->type()->id()) {
case SR_CHANNEL_LOGIC:
if (!signalbase) {
- signalbase = shared_ptr<data::SignalBase>(
- new data::SignalBase(channel));
+ signalbase = make_shared<data::SignalBase>(channel);
signalbases_.insert(signalbase);
all_signal_data_.insert(logic_data_);
signalbases_.insert(signalbase);
all_signal_data_.insert(logic_data_);
case SR_CHANNEL_ANALOG:
{
if (!signalbase) {
case SR_CHANNEL_ANALOG:
{
if (!signalbase) {
- signalbase = shared_ptr<data::SignalBase>(
- new data::SignalBase(channel));
+ signalbase = make_shared<data::SignalBase>(channel);
signalbases_.insert(signalbase);
shared_ptr<data::Analog> data(new data::Analog());
signalbases_.insert(signalbase);
shared_ptr<data::Analog> data(new data::Analog());
set_capture_state(Running);
// Create a new data segment
set_capture_state(Running);
// Create a new data segment
- cur_logic_segment_ = shared_ptr<data::LogicSegment>(
- new data::LogicSegment(*logic_data_, logic, cur_samplerate_));
+ cur_logic_segment_ = make_shared<data::LogicSegment>(
+ *logic_data_, logic, cur_samplerate_);
logic_data_->push_segment(cur_logic_segment_);
// @todo Putting this here means that only listeners querying
logic_data_->push_segment(cur_logic_segment_);
// @todo Putting this here means that only listeners querying
assert(data);
// Create a segment, keep it in the maps of channels
assert(data);
// Create a segment, keep it in the maps of channels
- segment = shared_ptr<data::AnalogSegment>(
- new data::AnalogSegment(*data, cur_samplerate_));
+ segment = make_shared<data::AnalogSegment>(
+ *data, cur_samplerate_);
cur_analog_segments_[channel] = segment;
// Push the segment into the analog data.
cur_analog_segments_[channel] = segment;
// Push the segment into the analog data.
using std::min;
using std::pair;
using std::shared_ptr;
using std::min;
using std::pair;
using std::shared_ptr;
using std::tie;
using std::unordered_set;
using std::vector;
using std::tie;
using std::unordered_set;
using std::vector;
assert(decoder);
assert(decoder_stack);
assert(decoder);
assert(decoder_stack);
- decoder_stack->push(shared_ptr<data::decode::Decoder>(
- new data::decode::Decoder(decoder)));
+ decoder_stack->push(make_shared<data::decode::Decoder>(decoder));
decoder_stack->begin_decode();
create_popup_form();
decoder_stack->begin_decode();
create_popup_form();
void View::add_flag(const Timestamp& time)
{
void View::add_flag(const Timestamp& time)
{
- flags_.push_back(shared_ptr<Flag>(new Flag(*this, time,
- QString("%1").arg(next_flag_text_))));
+ flags_.push_back(make_shared<Flag>(*this, time,
+ QString("%1").arg(next_flag_text_)));
next_flag_text_ = (next_flag_text_ >= 'Z') ? 'A' :
(next_flag_text_ + 1);
next_flag_text_ = (next_flag_text_ >= 'Z') ? 'A' :
(next_flag_text_ + 1);
void View::trigger_event(util::Timestamp location)
{
void View::trigger_event(util::Timestamp location)
{
- trigger_markers_.push_back(shared_ptr<TriggerMarker>(
- new TriggerMarker(*this, location)));
+ trigger_markers_.push_back(make_shared<TriggerMarker>(*this, location));
}
void View::get_scroll_layout(double &length, Timestamp &offset) const
}
void View::get_scroll_layout(double &length, Timestamp &offset) const