Remove unneeded heap allocation

This commit is contained in:
Cheng Zhao 2017-07-31 15:45:59 +09:00
parent 2d644a1560
commit a6c8329a68

View file

@ -268,11 +268,10 @@ v8::Local<v8::Value> NativeImage::ToPNG(mate::Arguments* args) {
const SkBitmap bitmap =
image_.AsImageSkia().GetRepresentation(scale_factor).sk_bitmap();
std::unique_ptr<std::vector<unsigned char>> encoded(
new std::vector<unsigned char>());
gfx::PNGCodec::EncodeBGRASkBitmap(bitmap, false, encoded.get());
const char* data = reinterpret_cast<char*>(encoded->data());
size_t size = encoded->size();
std::vector<unsigned char> encoded;
gfx::PNGCodec::EncodeBGRASkBitmap(bitmap, false, &encoded);
const char* data = reinterpret_cast<char*>(encoded.data());
size_t size = encoded.size();
return node::Buffer::Copy(args->isolate(), data, size).ToLocalChecked();
}