Skip to content

Commit

Permalink
use std::move() when possible
Browse files Browse the repository at this point in the history
  • Loading branch information
farindk committed Oct 22, 2024
1 parent e08c59b commit 86cbf80
Show file tree
Hide file tree
Showing 11 changed files with 27 additions and 35 deletions.
14 changes: 7 additions & 7 deletions libheif/api/libheif/heif.cc
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,7 @@ struct heif_error heif_context_get_image_handle(struct heif_context* ctx,
}

*imgHdl = new heif_image_handle();
(*imgHdl)->image = image;
(*imgHdl)->image = std::move(image);
(*imgHdl)->context = ctx->context;

return heif_error_success;
Expand Down Expand Up @@ -824,7 +824,7 @@ struct heif_error heif_image_handle_get_auxiliary_type(const struct heif_image_h

*out_type = nullptr;

auto auxType = handle->image->get_aux_type();
const auto& auxType = handle->image->get_aux_type();

char* buf = (char*) malloc(auxType.length() + 1);

Expand Down Expand Up @@ -2021,7 +2021,7 @@ struct heif_error heif_image_scale_image(const struct heif_image* input,
}

*output = new heif_image;
(*output)->image = out_img;
(*output)->image = std::move(out_img);

return Error::Ok.error_struct(input->image.get());
}
Expand Down Expand Up @@ -2501,7 +2501,7 @@ struct heif_error heif_image_handle_get_camera_intrinsic_matrix(const struct hei
return err.error_struct(handle->image.get());
}

auto m = handle->image->get_intrinsic_matrix();
const auto& m = handle->image->get_intrinsic_matrix();
out_matrix->focal_length_x = m.focal_length_x;
out_matrix->focal_length_y = m.focal_length_y;
out_matrix->principal_point_x = m.principal_point_x;
Expand Down Expand Up @@ -3430,7 +3430,7 @@ struct heif_error heif_context_encode_image(struct heif_context* ctx,

if (out_image_handle) {
*out_image_handle = new heif_image_handle;
(*out_image_handle)->image = image;
(*out_image_handle)->image = std::move(image);
(*out_image_handle)->context = ctx->context;
}

Expand Down Expand Up @@ -3501,7 +3501,7 @@ struct heif_error heif_context_encode_grid(struct heif_context* ctx,

if (out_image_handle) {
*out_image_handle = new heif_image_handle;
(*out_image_handle)->image = out_grid;
(*out_image_handle)->image = std::move(out_grid);
(*out_image_handle)->context = ctx->context;
}

Expand Down Expand Up @@ -3593,7 +3593,7 @@ struct heif_error heif_context_add_overlay_image(struct heif_context* ctx,

if (out_iovl_image_handle) {
*out_iovl_image_handle = new heif_image_handle;
(*out_iovl_image_handle)->image = iovlimage;
(*out_iovl_image_handle)->image = std::move(iovlimage);
(*out_iovl_image_handle)->context = ctx->context;
}

Expand Down
2 changes: 1 addition & 1 deletion libheif/api/libheif/heif_properties.cc
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ struct heif_error heif_item_get_property_raw_size(const struct heif_context* con
return {heif_error_Usage_error, heif_suberror_Invalid_property, "this property is not read as a raw box"};
}

auto data = box_other->get_raw_data();
const auto& data = box_other->get_raw_data();

*size_out = data.size();

Expand Down
6 changes: 3 additions & 3 deletions libheif/api/libheif/heif_regions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include <cstring>
#include <memory>
#include <vector>
#include <algorithm>
#include <utility>


int heif_image_handle_get_number_of_region_items(const struct heif_image_handle* handle)
Expand Down Expand Up @@ -65,7 +65,7 @@ struct heif_error heif_context_get_region_item(const struct heif_context* contex

heif_region_item* item = new heif_region_item();
item->context = context->context;
item->region_item = r;
item->region_item = std::move(r);
*out = item;

return heif_error_success;
Expand Down Expand Up @@ -133,7 +133,7 @@ struct heif_error heif_image_handle_add_region_item(struct heif_image_handle* im
if (out_region_item) {
heif_region_item* item = new heif_region_item();
item->context = image_handle->context;
item->region_item = regionItem;
item->region_item = std::move(regionItem);

*out_region_item = item;
}
Expand Down
3 changes: 2 additions & 1 deletion libheif/box.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <cinttypes>
#include <cstddef>

#include <utility>
#include <vector>
#include <string>
#include <memory>
Expand Down Expand Up @@ -350,7 +351,7 @@ class Box_Error : public Box
set_short_type(fourcc("ERR "));

m_box_type_with_parse_error = box4cc;
m_error = err;
m_error = std::move(err);
m_fatality = fatality;
}

Expand Down
4 changes: 3 additions & 1 deletion libheif/codecs/decoder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
*/

#include "codecs/decoder.h"

#include <utility>
#include "error.h"
#include "context.h"
#include "plugin_registry.h"
Expand All @@ -41,7 +43,7 @@

void DataExtent::set_from_image_item(std::shared_ptr<HeifFile> file, heif_item_id item)
{
m_file = file;
m_file = std::move(file);
m_item_id = item;
m_source = Source::Image;
}
Expand Down
3 changes: 2 additions & 1 deletion libheif/codecs/jpeg2000_boxes.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <string>
#include <vector>
#include <memory>
#include <utility>

/**
* JPEG 2000 Channel Definition box.
Expand Down Expand Up @@ -446,7 +447,7 @@ struct JPEG2000MainHeader
Error doParse();
void setHeaderData(std::vector<uint8_t> data)
{
headerData = data;
headerData = std::move(data);
}

heif_chroma get_chroma_format() const;
Expand Down
2 changes: 1 addition & 1 deletion libheif/codecs/uncompressed/decoder_abstract.cc
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ const Error AbstractDecoder::get_compressed_image_data_uncompressed(const HeifCo
auto unit_end = unit_start + unit_info.unit_size;
std::vector<uint8_t> compressed_unit_data = std::vector<uint8_t>(unit_start, unit_end);
std::vector<uint8_t> uncompressed_unit_data;
err = do_decompress_data(cmpC_box, compressed_unit_data, &uncompressed_unit_data);
err = do_decompress_data(cmpC_box, std::move(compressed_unit_data), &uncompressed_unit_data);
if (err) {
return err;
}
Expand Down
19 changes: 3 additions & 16 deletions libheif/context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ void HeifContext::remove_top_level_image(const std::shared_ptr<ImageItem>& image
}
}

m_top_level_images = new_list;
m_top_level_images = std::move(new_list);
}


Expand Down Expand Up @@ -545,20 +545,7 @@ Error HeifContext::interpret_heif_file()
// --- this is an auxiliary image
// check whether it is an alpha channel and attach to the main image if yes

std::vector<std::shared_ptr<Box>> properties;
Error err = m_heif_file->get_properties(image->get_id(), properties);
if (err) {
return err;
}

std::shared_ptr<Box_auxC> auxC_property;
for (const auto& property : properties) {
auto auxC = std::dynamic_pointer_cast<Box_auxC>(property);
if (auxC) {
auxC_property = auxC;
}
}

std::shared_ptr<Box_auxC> auxC_property = m_heif_file->get_property<Box_auxC>(image->get_id());
if (!auxC_property) {
std::stringstream sstr;
sstr << "No auxC property for image " << image->get_id();
Expand Down Expand Up @@ -630,7 +617,7 @@ Error HeifContext::interpret_heif_file()
const auto& subtypes = auxC_property->get_subtypes();

std::vector<std::shared_ptr<SEIMessage>> sei_messages;
err = decode_hevc_aux_sei_messages(subtypes, sei_messages);
Error err = decode_hevc_aux_sei_messages(subtypes, sei_messages);
if (err) {
return err;
}
Expand Down
2 changes: 1 addition & 1 deletion libheif/file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1157,7 +1157,7 @@ Result<heif_item_id> HeifFile::add_precompressed_infe_mime(const char* content_t
heif_item_id metadata_id = infe_box->get_item_ID();
result.value = metadata_id;

set_precompressed_item_data(infe_box, data, size, content_encoding);
set_precompressed_item_data(infe_box, data, size, std::move(content_encoding));

return result;
}
Expand Down
2 changes: 1 addition & 1 deletion libheif/image-items/jpeg.cc
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ Result<ImageItem::CodedImageData> ImageItem_JPEG::encode(const std::shared_ptr<H
#endif
(void) JPEG_SOS;

codedImage.bitstream = vec;
codedImage.bitstream = std::move(vec);

#if 0
// TODO: extract 'jpgC' header data
Expand Down
5 changes: 3 additions & 2 deletions libheif/plugins/encoder_aom.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <string>
#include <thread>
#include <memory>
#include <utility>
#include "encoder_aom.h"

#include <aom/aom_encoder.h>
Expand Down Expand Up @@ -125,8 +126,8 @@ void encoder_struct_aom::add_custom_option(const custom_option& p)
void encoder_struct_aom::add_custom_option(std::string name, std::string value)
{
custom_option p;
p.name = name;
p.value = value;
p.name = std::move(name);
p.value = std::move(value);
add_custom_option(p);
}

Expand Down

0 comments on commit 86cbf80

Please sign in to comment.