Use std::make_shared to allocate shared ptrs

std::make_shared does in a single allocation what the constructors
for std::shared_ptr usually take at least 2 allocations to do.
May give us an infinitesimal performance/memory improvement.

https://www.modernescpp.com/index.php/memory-and-performance-overhead-of-smart-pointer
This commit is contained in:
FeRD (Frank Dana)
2020-08-20 16:50:12 -04:00
parent d121f9dc0d
commit 3c2532b4de
19 changed files with 129 additions and 78 deletions

View File

@@ -61,7 +61,7 @@ void ImageReader::Open()
try
{
// load image
image = std::shared_ptr<Magick::Image>(new Magick::Image(path));
image = std::make_shared<Magick::Image>(path);
// Give image a transparent background color
image->backgroundColor(Magick::Color("none"));
@@ -126,7 +126,9 @@ std::shared_ptr<Frame> ImageReader::GetFrame(int64_t requested_frame)
throw ReaderClosed("The FFmpegReader is closed. Call Open() before calling this method.", path);
// Create or get frame object
std::shared_ptr<Frame> image_frame(new Frame(requested_frame, image->size().width(), image->size().height(), "#000000", 0, 2));
auto image_frame = std::make_shared<Frame>(
requested_frame, image->size().width(), image->size().height(),
"#000000", 0, 2);
// Add Image data to frame
image_frame->AddMagickImage(image);