Minor unique_ptr initialization cleanup (flutter/engine#32821)

Cleans up a few cases of std::unique_ptr(new T) that could have been
using std::make_unique<T>(...).
This commit is contained in:
Chris Bracken
2022-04-20 17:08:00 -07:00
committed by GitHub
parent 7bdc84940d
commit a970f9766a
7 changed files with 12 additions and 12 deletions

View File

@@ -203,9 +203,8 @@ void PlatformConfiguration::DidCreateIsolate() {
Dart_GetField(library, tonic::ToDart("_drawFrame")));
report_timings_.Set(tonic::DartState::Current(),
Dart_GetField(library, tonic::ToDart("_reportTimings")));
windows_.insert(
std::make_pair(0, std::unique_ptr<Window>(new Window{
0, ViewportMetrics{1.0, 0.0, 0.0, -1}})));
windows_.insert(std::make_pair(
0, std::make_unique<Window>(0, ViewportMetrics{1.0, 0.0, 0.0, -1})));
}
void PlatformConfiguration::UpdateLocales(

View File

@@ -115,7 +115,8 @@ TEST(FlutterWindowsTextureRegistrarTest, PopulatePixelBufferTexture) {
bool release_callback_called = false;
size_t width = 100;
size_t height = 100;
std::unique_ptr<uint8_t[]> pixels(new uint8_t[width * height * 4]);
std::unique_ptr<uint8_t[]> pixels =
std::make_unique<uint8_t[]>(width * height * 4);
FlutterDesktopPixelBuffer pixel_buffer = {};
pixel_buffer.width = width;
pixel_buffer.height = height;

View File

@@ -3,6 +3,7 @@
// found in the LICENSE file.
#include <cassert>
#include <memory>
#include <optional>
#include "flutter/fml/logging.h"
@@ -50,10 +51,9 @@ TestVulkanContext::TestVulkanContext() {
return;
}
application_ =
std::unique_ptr<vulkan::VulkanApplication>(new vulkan::VulkanApplication(
*vk_, "Flutter Unittests", {}, VK_MAKE_VERSION(1, 0, 0),
VK_MAKE_VERSION(1, 0, 0), true));
application_ = std::make_unique<vulkan::VulkanApplication>(
*vk_, "Flutter Unittests", std::vector<std::string>{},
VK_MAKE_VERSION(1, 0, 0), VK_MAKE_VERSION(1, 0, 0), true);
if (!application_->IsValid()) {
FML_LOG(ERROR) << "Failed to initialize basic Vulkan state.";
return;

View File

@@ -18,7 +18,7 @@ template <typename... Args>
std::string StringPrintf(const std::string& format, Args... args) {
// Calculate the buffer size.
int size = snprintf(nullptr, 0, format.c_str(), args...) + 1;
std::unique_ptr<char[]> buf(new char[size]);
std::unique_ptr<char[]> buf = std::make_unique<char[]>(size);
snprintf(buf.get(), size, format.c_str(), args...);
return std::string(buf.get(), buf.get() + size - 1);
}

View File

@@ -27,7 +27,7 @@ void Log(const char* format, ...) {
}
int size = result + 1;
std::unique_ptr<char[]> message(new char[size]);
std::unique_ptr<char[]> message = std::make_unique<char[]>(size);
va_start(ap, format);
result = vsnprintf(message.get(), size, format, ap);
va_end(ap);

View File

@@ -195,7 +195,7 @@ void ParagraphBuilderSkia::AddPlaceholder(PlaceholderRun& span) {
}
std::unique_ptr<Paragraph> ParagraphBuilderSkia::Build() {
return std::unique_ptr<Paragraph>(new ParagraphSkia(builder_->Build()));
return std::make_unique<ParagraphSkia>(builder_->Build());
}
} // namespace txt

View File

@@ -95,7 +95,7 @@ void ParseUnicode(uint16_t* buf,
std::vector<uint16_t> parseUnicodeStringWithOffset(const std::string& in,
size_t* offset) {
std::unique_ptr<uint16_t[]> buffer(new uint16_t[in.size()]);
std::unique_ptr<uint16_t[]> buffer = std::make_unique<uint16_t[]>(in.size());
size_t result_size = 0;
ParseUnicode(buffer.get(), in.size(), in.c_str(), &result_size, offset);
return std::vector<uint16_t>(buffer.get(), buffer.get() + result_size);