Commit 7f711827 for libheif
commit 7f7118279056f67a824e9959aef7c44e7de0ef8d
Author: Dirk Farin <dirk.farin@gmail.com>
Date: Thu Aug 27 00:57:47 2026 +0200
apply the clang-tidy performance-* fixes
Preparation for enabling the performance-* checks in .clang-tidy (they
were listed there for years but never took effect, see the next commit).
Fixed with clang-tidy 18 --fix-errors followed by a manual review:
- pass std::string, std::shared_ptr and struct parameters that are only
read by const reference, in the declarations as well
(performance-unnecessary-value-param)
- std::move sink parameters into members instead of copying them
- bind range-for loop variables by const reference
(performance-for-range-copy)
- reserve() before push_back loops with a known size
(performance-inefficient-vector-operation)
- drop std::move where it cannot move: const references and trivially
copyable types (performance-move-const-arg)
- do not declare returned locals const, so the return can move
(performance-no-automatic-move)
- '\n' instead of std::endl, += instead of + chains, find('c') instead
of find("c") (performance-avoid-endl, -inefficient-string-concatenation,
-faster-string-find)
- mark the four casts of an integer to the codecs' opaque user-data
pointer as intentional (performance-no-int-to-ptr)
The public C API is untouched: no header under libheif/api changes, and
the exported heif_* symbol table of a reduced-visibility build is
identical before and after. Only internal C++ signatures change.
diff --git a/examples/heif_dec.cc b/examples/heif_dec.cc
index 028a08ac..a14471d9 100644
--- a/examples/heif_dec.cc
+++ b/examples/heif_dec.cc
@@ -261,8 +261,8 @@ std::string sanitizeFilename(const std::string& filename) {
int decode_single_image(heif_image_handle* handle,
- std::string filename_stem,
- std::string filename_suffix,
+ const std::string& filename_stem,
+ const std::string& filename_suffix,
heif_decoding_options* decode_options,
std::unique_ptr<Encoder>& encoder)
{
@@ -526,8 +526,8 @@ int digits_for_integer(uint32_t v)
int decode_image_tiles(heif_image_handle* handle,
- std::string filename_stem,
- std::string filename_suffix,
+ const std::string& filename_stem,
+ const std::string& filename_suffix,
heif_decoding_options* decode_options,
std::unique_ptr<Encoder>& encoder)
{
diff --git a/examples/heif_enc.cc b/examples/heif_enc.cc
index d94d667e..e8f0fc2d 100644
--- a/examples/heif_enc.cc
+++ b/examples/heif_enc.cc
@@ -956,7 +956,7 @@ InputImage load_image(const std::string& input_filename, int output_bit_depth)
heif_error create_output_nclx_profile_and_configure_encoder(heif_encoder* encoder,
heif_color_profile_nclx** out_nclx,
- std::shared_ptr<heif_image> input_image,
+ const std::shared_ptr<heif_image>& input_image,
bool lossless,
heif_output_nclx_color_profile_preset profile_preset)
{
@@ -1242,7 +1242,7 @@ public:
heif_get_global_security_limits(),
&tileImage);
if (err.code) {
- std::cerr << "error extracting tile " << tx << ";" << ty << std::endl;
+ std::cerr << "error extracting tile " << tx << ";" << ty << '\n';
exit(1);
}
@@ -1416,7 +1416,7 @@ heif_image_handle* encode_tiled(heif_context* ctx, heif_encoder* encoder, heif_e
template <typename T>
-std::vector<T> parse_comma_separated_numeric_arguments(std::string arg,
+std::vector<T> parse_comma_separated_numeric_arguments(const std::string& arg,
std::vector<T> max_val)
{
std::istringstream ss(arg);
@@ -2265,7 +2265,7 @@ int do_encode_images(heif_context* context, heif_encoder* encoder, heif_encoding
std::vector<heif_item_id> encoded_image_ids;
- for (std::string input_filename : args) {
+ for (const std::string& input_filename : args) {
InputImage input_image;
heif_image_tiling tiling{};
@@ -2704,7 +2704,7 @@ int do_encode_sequence(heif_context* context, heif_encoder* encoder, heif_encodi
heif_track* track = nullptr;
heif_sequence_encoding_options* encoding_options = nullptr;
- for (std::string input_filename : args) {
+ for (const std::string& input_filename : args) {
currImage++;
if (currImage > nImages) {
break;
diff --git a/examples/heif_info.cc b/examples/heif_info.cc
index 3a9ce68d..a2332fb8 100644
--- a/examples/heif_info.cc
+++ b/examples/heif_info.cc
@@ -560,13 +560,17 @@ int main(int argc, char** argv)
ID = itemtype;
}
else if (itemtype == "uri ") {
- ID = itemtype + "/" + item_uri_type;
+ ID = itemtype;
+ ID += "/";
+ ID += item_uri_type;
}
else if (contenttype == "application/rdf+xml") {
ID = "XMP";
}
else {
- ID = itemtype + "/" + contenttype;
+ ID = itemtype;
+ ID += "/";
+ ID += contenttype;
}
printf(" %s: %zu bytes\n", ID.c_str(), heif_image_handle_get_metadata_size(handle, ids[n]));
diff --git a/libheif/api/libheif/heif_properties.cc b/libheif/api/libheif/heif_properties.cc
index 1d58edf3..d43a5d0d 100644
--- a/libheif/api/libheif/heif_properties.cc
+++ b/libheif/api/libheif/heif_properties.cc
@@ -135,7 +135,7 @@ heif_item_property_type heif_item_get_property_type(const heif_context* context,
}
-static char* create_c_string_copy(const std::string s)
+static char* create_c_string_copy(const std::string& s)
{
char* copy = new char[s.length() + 1];
strcpy(copy, s.data());
diff --git a/libheif/api/libheif/heif_tiling.cc b/libheif/api/libheif/heif_tiling.cc
index 2cc3cdaf..f0f5c9c8 100644
--- a/libheif/api/libheif/heif_tiling.cc
+++ b/libheif/api/libheif/heif_tiling.cc
@@ -193,6 +193,7 @@ heif_error heif_context_encode_grid(heif_context* ctx,
// Convert heif_images to a vector of HeifPixelImages
std::vector<std::shared_ptr<HeifPixelImage> > pixel_tiles;
+ pixel_tiles.reserve(rows * columns);
for (int i = 0; i < rows * columns; i++) {
pixel_tiles.push_back(tiles[i]->image);
}
diff --git a/libheif/box.h b/libheif/box.h
index 35025ddb..f3b099bb 100644
--- a/libheif/box.h
+++ b/libheif/box.h
@@ -1761,7 +1761,7 @@ public:
* An RFC 5646 compliant language identifier for the language of the text contained in the other properties.
* Examples: "en-AU", "de-DE", or "zh-CN“.
*/
- void set_lang(const std::string lang) { m_lang = lang; }
+ void set_lang(const std::string& lang) { m_lang = lang; }
/**
* Name.
@@ -1776,7 +1776,7 @@ public:
*
* Human readable name for the item or group being described.
*/
- void set_name(const std::string name) { m_name = name; }
+ void set_name(const std::string& name) { m_name = name; }
/**
* Description.
@@ -1791,7 +1791,7 @@ public:
*
* Human readable description for the item or group.
*/
- void set_description(const std::string description) { m_description = description; }
+ void set_description(const std::string& description) { m_description = description; }
/**
* Tags.
@@ -1806,7 +1806,7 @@ public:
*
* Comma separated user defined tags applicable to the item or group.
*/
- void set_tags(const std::string tags) { m_tags = tags; }
+ void set_tags(const std::string& tags) { m_tags = tags; }
[[nodiscard]] parse_error_fatality get_parse_error_fatality() const override { return parse_error_fatality::optional; }
@@ -2041,7 +2041,7 @@ public:
* An RFC 5646 (IETF BCP 47) compliant language identifier for the language of the text.
* Examples: "en-AU", "de-DE", or "zh-CN“.
*/
- void set_lang(const std::string lang) { m_lang = lang; }
+ void set_lang(const std::string& lang) { m_lang = lang; }
[[nodiscard]] parse_error_fatality get_parse_error_fatality() const override { return parse_error_fatality::optional; }
diff --git a/libheif/codecs/avc_enc.cc b/libheif/codecs/avc_enc.cc
index e9fed1a3..955ecdf2 100644
--- a/libheif/codecs/avc_enc.cc
+++ b/libheif/codecs/avc_enc.cc
@@ -291,7 +291,7 @@ std::shared_ptr<Box_VisualSampleEntry> Encoder_AVC::get_sample_description_box(c
auto avc1 = std::make_shared<Box_avc1>();
avc1->get_VisualSampleEntry().compressorname = "AVC";
- for (auto prop : data.properties) {
+ for (const auto& prop : data.properties) {
if (prop->get_short_type() == fourcc("avcC")) {
avc1->append_child_box(prop);
return avc1;
diff --git a/libheif/codecs/avif_enc.cc b/libheif/codecs/avif_enc.cc
index 800494e9..dba271cb 100644
--- a/libheif/codecs/avif_enc.cc
+++ b/libheif/codecs/avif_enc.cc
@@ -210,7 +210,7 @@ std::shared_ptr<Box_VisualSampleEntry> Encoder_AVIF::get_sample_description_box(
auto av01 = std::make_shared<Box_av01>();
av01->get_VisualSampleEntry().compressorname = "AVIF";
- for (auto prop : data.properties) {
+ for (const auto& prop : data.properties) {
if (prop->get_short_type() == fourcc("av1C")) {
av01->append_child_box(prop);
return av01;
diff --git a/libheif/codecs/decoder.cc b/libheif/codecs/decoder.cc
index 0e01347c..69a8a08f 100644
--- a/libheif/codecs/decoder.cc
+++ b/libheif/codecs/decoder.cc
@@ -207,7 +207,7 @@ std::shared_ptr<Decoder> Decoder::alloc_for_infe_type(const ImageItem* item)
}
-std::shared_ptr<Decoder> Decoder::alloc_for_sequence_sample_description_box(std::shared_ptr<const Box_VisualSampleEntry> sample_description_box)
+std::shared_ptr<Decoder> Decoder::alloc_for_sequence_sample_description_box(const std::shared_ptr<const Box_VisualSampleEntry>& sample_description_box)
{
std::string compressor = sample_description_box->get_VisualSampleEntry_const().compressorname;
uint32_t sampleType = sample_description_box->get_short_type();
diff --git a/libheif/codecs/decoder.h b/libheif/codecs/decoder.h
index a45d012f..7435badf 100644
--- a/libheif/codecs/decoder.h
+++ b/libheif/codecs/decoder.h
@@ -82,7 +82,7 @@ class Decoder
public:
static std::shared_ptr<Decoder> alloc_for_infe_type(const ImageItem* item);
- static std::shared_ptr<Decoder> alloc_for_sequence_sample_description_box(std::shared_ptr<const class Box_VisualSampleEntry> sample_description_box);
+ static std::shared_ptr<Decoder> alloc_for_sequence_sample_description_box(const std::shared_ptr<const class Box_VisualSampleEntry>& sample_description_box);
virtual ~Decoder();
diff --git a/libheif/codecs/hevc_boxes.cc b/libheif/codecs/hevc_boxes.cc
index 18bd08ae..a185cb5a 100644
--- a/libheif/codecs/hevc_boxes.cc
+++ b/libheif/codecs/hevc_boxes.cc
@@ -353,7 +353,7 @@ void Box_hvcC::append_nal_data(const std::vector<uint8_t>& nal)
// If they are similar, keep the smaller one.
if (nal_unit.size() > nal.size()) {
- nal_unit = std::move(nal);
+ nal_unit = nal;
}
// Exit. Do not add a copy of the packet.
@@ -362,7 +362,7 @@ void Box_hvcC::append_nal_data(const std::vector<uint8_t>& nal)
}
}
- nal_array.m_nal_units.push_back(std::move(nal));
+ nal_array.m_nal_units.push_back(nal);
return;
}
@@ -373,7 +373,7 @@ void Box_hvcC::append_nal_data(const std::vector<uint8_t>& nal)
HEVCDecoderConfigurationRecord::NalArray array;
array.m_array_completeness = 1;
array.m_NAL_unit_type = uint8_t(nal[0] >> 1);
- array.m_nal_units.push_back(std::move(nal));
+ array.m_nal_units.push_back(nal);
m_configuration.m_nal_array.push_back(array);
}
diff --git a/libheif/codecs/hevc_enc.cc b/libheif/codecs/hevc_enc.cc
index 293b27c6..e6cc45fc 100644
--- a/libheif/codecs/hevc_enc.cc
+++ b/libheif/codecs/hevc_enc.cc
@@ -297,7 +297,7 @@ std::shared_ptr<Box_VisualSampleEntry> Encoder_HEVC::get_sample_description_box(
auto hvc1 = std::make_shared<Box_hvc1>();
hvc1->get_VisualSampleEntry().compressorname = "HEVC";
- for (auto prop : data.properties) {
+ for (const auto& prop : data.properties) {
if (prop->get_short_type() == fourcc("hvcC")) {
hvc1->append_child_box(prop);
return hvc1;
diff --git a/libheif/codecs/jpeg2000_boxes.h b/libheif/codecs/jpeg2000_boxes.h
index d6b5c306..a9f53703 100644
--- a/libheif/codecs/jpeg2000_boxes.h
+++ b/libheif/codecs/jpeg2000_boxes.h
@@ -228,7 +228,7 @@ public:
return (uint8_t)(m_bitDepths.size());
}
- void add_entry(const PaletteEntry entry)
+ void add_entry(const PaletteEntry& entry)
{
m_entries.push_back(entry);
}
diff --git a/libheif/codecs/jpeg2000_enc.cc b/libheif/codecs/jpeg2000_enc.cc
index bc118403..e55c8a60 100644
--- a/libheif/codecs/jpeg2000_enc.cc
+++ b/libheif/codecs/jpeg2000_enc.cc
@@ -83,7 +83,7 @@ std::shared_ptr<class Box_VisualSampleEntry> Encoder_JPEG2000::get_sample_descri
auto j2ki = std::make_shared<Box_j2ki>();
j2ki->get_VisualSampleEntry().compressorname = "JPEG2000";
- for (auto prop : data.properties) {
+ for (const auto& prop : data.properties) {
if (prop->get_short_type() == fourcc("j2kH")) {
j2ki->append_child_box(prop);
return j2ki;
@@ -100,7 +100,7 @@ std::shared_ptr<class Box_VisualSampleEntry> Encoder_HTJ2K::get_sample_descripti
auto j2ki = std::make_shared<Box_j2ki>();
j2ki->get_VisualSampleEntry().compressorname = "HTJ2K";
- for (auto prop : data.properties) {
+ for (const auto& prop : data.properties) {
if (prop->get_short_type() == fourcc("j2kH")) {
j2ki->append_child_box(prop);
return j2ki;
diff --git a/libheif/codecs/jpeg_dec.cc b/libheif/codecs/jpeg_dec.cc
index f43e8184..a7aa43fd 100644
--- a/libheif/codecs/jpeg_dec.cc
+++ b/libheif/codecs/jpeg_dec.cc
@@ -58,7 +58,7 @@ Error Decoder_JPEG::parse_SOF()
const std::vector<uint8_t>& data = *dataResult;
- const Error error_invalidSOF{heif_error_Invalid_input,
+ Error error_invalidSOF{heif_error_Invalid_input,
heif_suberror_Unspecified,
"Invalid JPEG SOF header"};
diff --git a/libheif/codecs/jpeg_enc.cc b/libheif/codecs/jpeg_enc.cc
index 8b1bd31b..98741ec3 100644
--- a/libheif/codecs/jpeg_enc.cc
+++ b/libheif/codecs/jpeg_enc.cc
@@ -124,7 +124,7 @@ std::shared_ptr<class Box_VisualSampleEntry> Encoder_JPEG::get_sample_descriptio
auto mjpg = std::make_shared<Box_mjpg>();
mjpg->get_VisualSampleEntry().compressorname = "JPEG";
- for (auto prop : data.properties) {
+ for (const auto& prop : data.properties) {
if (prop->get_short_type() == fourcc("jpgC")) {
mjpg->append_child_box(prop);
}
diff --git a/libheif/codecs/uncompressed/unc_codec.cc b/libheif/codecs/uncompressed/unc_codec.cc
index de4200c3..00f8af1d 100644
--- a/libheif/codecs/uncompressed/unc_codec.cc
+++ b/libheif/codecs/uncompressed/unc_codec.cc
@@ -294,6 +294,7 @@ Result<std::shared_ptr<HeifPixelImage>> UncompressedImageCodec::create_image(con
if (properties.cpat) {
const auto& pattern_cmpd = properties.cpat->get_pattern();
std::vector<uint32_t> cpat_indices;
+ cpat_indices.reserve(pattern_cmpd.pixels.size());
for (const auto& pixel : pattern_cmpd.pixels) {
cpat_indices.push_back(pixel.cmpd_index);
}
diff --git a/libheif/codecs/uncompressed/unc_decoder.cc b/libheif/codecs/uncompressed/unc_decoder.cc
index 48cae1f8..cb0c6c44 100644
--- a/libheif/codecs/uncompressed/unc_decoder.cc
+++ b/libheif/codecs/uncompressed/unc_decoder.cc
@@ -193,7 +193,7 @@ const Error unc_decoder::get_compressed_image_data_uncompressed(const DataExtent
auto unit_end = unit_start + unit_info.unit_size;
std::vector<uint8_t> compressed_unit_data = std::vector<uint8_t>(unit_start, unit_end);
- auto dataResult = do_decompress_data(cmpC_box, std::move(compressed_unit_data), limits);
+ auto dataResult = do_decompress_data(cmpC_box, compressed_unit_data, limits);
if (!dataResult) {
return dataResult.error();
}
@@ -261,7 +261,7 @@ const Error unc_decoder::get_compressed_image_data_uncompressed(const DataExtent
Result<std::vector<uint8_t> > unc_decoder::do_decompress_data(std::shared_ptr<const Box_cmpC>& cmpC_box,
- std::vector<uint8_t> compressed_data,
+ const std::vector<uint8_t>& compressed_data,
const heif_security_limits* limits) const
{
if (cmpC_box->get_compression_type() == fourcc("brot")) {
@@ -299,7 +299,7 @@ Result<std::vector<uint8_t> > unc_decoder::do_decompress_data(std::shared_ptr<co
}
else {
std::stringstream sstr;
- sstr << "cannot decode unci item with unsupported compression type: " << cmpC_box->get_compression_type() << std::endl;
+ sstr << "cannot decode unci item with unsupported compression type: " << cmpC_box->get_compression_type() << '\n';
return Error(heif_error_Unsupported_feature,
heif_suberror_Unsupported_generic_compression_method,
sstr.str());
diff --git a/libheif/codecs/uncompressed/unc_decoder.h b/libheif/codecs/uncompressed/unc_decoder.h
index 49e4d994..9d1fc205 100644
--- a/libheif/codecs/uncompressed/unc_decoder.h
+++ b/libheif/codecs/uncompressed/unc_decoder.h
@@ -75,7 +75,7 @@ protected:
const Box_iloc::Item* item) const;
Result<std::vector<uint8_t>> do_decompress_data(std::shared_ptr<const Box_cmpC>& cmpC_box,
- std::vector<uint8_t> compressed_data,
+ const std::vector<uint8_t>& compressed_data,
const heif_security_limits* limits) const;
const uint32_t m_width;
diff --git a/libheif/codecs/uncompressed/unc_decoder_block_component_interleave.cc b/libheif/codecs/uncompressed/unc_decoder_block_component_interleave.cc
index fd2f7f72..81e044fb 100644
--- a/libheif/codecs/uncompressed/unc_decoder_block_component_interleave.cc
+++ b/libheif/codecs/uncompressed/unc_decoder_block_component_interleave.cc
@@ -32,8 +32,8 @@
unc_decoder_block_component_interleave::unc_decoder_block_component_interleave(
uint32_t width, uint32_t height,
- std::shared_ptr<const Box_cmpd> cmpd,
- std::shared_ptr<const Box_uncC> uncC,
+ const std::shared_ptr<const Box_cmpd>& cmpd,
+ const std::shared_ptr<const Box_uncC>& uncC,
const std::vector<uint32_t>& uncC_index_to_comp_ids)
: unc_decoder(width, height, cmpd, uncC, uncC_index_to_comp_ids)
{
diff --git a/libheif/codecs/uncompressed/unc_decoder_block_component_interleave.h b/libheif/codecs/uncompressed/unc_decoder_block_component_interleave.h
index 0ced4fca..eafc3dd3 100644
--- a/libheif/codecs/uncompressed/unc_decoder_block_component_interleave.h
+++ b/libheif/codecs/uncompressed/unc_decoder_block_component_interleave.h
@@ -30,8 +30,8 @@ class unc_decoder_block_component_interleave : public unc_decoder
{
public:
unc_decoder_block_component_interleave(uint32_t width, uint32_t height,
- std::shared_ptr<const Box_cmpd> cmpd,
- std::shared_ptr<const Box_uncC> uncC,
+ const std::shared_ptr<const Box_cmpd>& cmpd,
+ const std::shared_ptr<const Box_uncC>& uncC,
const std::vector<uint32_t>& uncC_index_to_comp_ids);
Result<std::vector<uint64_t>> get_tile_data_sizes() const override;
diff --git a/libheif/codecs/uncompressed/unc_decoder_block_pixel_interleave.cc b/libheif/codecs/uncompressed/unc_decoder_block_pixel_interleave.cc
index 9ad9b006..2bee68dc 100644
--- a/libheif/codecs/uncompressed/unc_decoder_block_pixel_interleave.cc
+++ b/libheif/codecs/uncompressed/unc_decoder_block_pixel_interleave.cc
@@ -32,8 +32,8 @@
unc_decoder_block_pixel_interleave::unc_decoder_block_pixel_interleave(
uint32_t width, uint32_t height,
- std::shared_ptr<const Box_cmpd> cmpd,
- std::shared_ptr<const Box_uncC> uncC,
+ const std::shared_ptr<const Box_cmpd>& cmpd,
+ const std::shared_ptr<const Box_uncC>& uncC,
const std::vector<uint32_t>& uncC_index_to_comp_ids)
: unc_decoder(width, height, cmpd, uncC, uncC_index_to_comp_ids)
{
diff --git a/libheif/codecs/uncompressed/unc_decoder_block_pixel_interleave.h b/libheif/codecs/uncompressed/unc_decoder_block_pixel_interleave.h
index dd1ab29f..7d44026f 100644
--- a/libheif/codecs/uncompressed/unc_decoder_block_pixel_interleave.h
+++ b/libheif/codecs/uncompressed/unc_decoder_block_pixel_interleave.h
@@ -30,8 +30,8 @@ class unc_decoder_block_pixel_interleave : public unc_decoder
{
public:
unc_decoder_block_pixel_interleave(uint32_t width, uint32_t height,
- std::shared_ptr<const Box_cmpd> cmpd,
- std::shared_ptr<const Box_uncC> uncC,
+ const std::shared_ptr<const Box_cmpd>& cmpd,
+ const std::shared_ptr<const Box_uncC>& uncC,
const std::vector<uint32_t>& uncC_index_to_comp_ids);
Result<std::vector<uint64_t>> get_tile_data_sizes() const override;
diff --git a/libheif/codecs/uncompressed/unc_decoder_bytealign_component_interleave.cc b/libheif/codecs/uncompressed/unc_decoder_bytealign_component_interleave.cc
index 7c557703..55a2be00 100644
--- a/libheif/codecs/uncompressed/unc_decoder_bytealign_component_interleave.cc
+++ b/libheif/codecs/uncompressed/unc_decoder_bytealign_component_interleave.cc
@@ -32,8 +32,8 @@
unc_decoder_bytealign_component_interleave::unc_decoder_bytealign_component_interleave(
uint32_t width, uint32_t height,
- std::shared_ptr<const Box_cmpd> cmpd,
- std::shared_ptr<const Box_uncC> uncC,
+ const std::shared_ptr<const Box_cmpd>& cmpd,
+ const std::shared_ptr<const Box_uncC>& uncC,
const std::vector<uint32_t>& uncC_index_to_comp_ids)
: unc_decoder(width, height, cmpd, uncC, uncC_index_to_comp_ids)
{
diff --git a/libheif/codecs/uncompressed/unc_decoder_bytealign_component_interleave.h b/libheif/codecs/uncompressed/unc_decoder_bytealign_component_interleave.h
index 1bd8db13..f1c1927b 100644
--- a/libheif/codecs/uncompressed/unc_decoder_bytealign_component_interleave.h
+++ b/libheif/codecs/uncompressed/unc_decoder_bytealign_component_interleave.h
@@ -30,8 +30,8 @@ class unc_decoder_bytealign_component_interleave : public unc_decoder
{
public:
unc_decoder_bytealign_component_interleave(uint32_t width, uint32_t height,
- std::shared_ptr<const Box_cmpd> cmpd,
- std::shared_ptr<const Box_uncC> uncC,
+ const std::shared_ptr<const Box_cmpd>& cmpd,
+ const std::shared_ptr<const Box_uncC>& uncC,
const std::vector<uint32_t>& uncC_index_to_comp_ids);
Result<std::vector<uint64_t>> get_tile_data_sizes() const override;
diff --git a/libheif/codecs/uncompressed/unc_decoder_component_interleave.h b/libheif/codecs/uncompressed/unc_decoder_component_interleave.h
index cb5a1702..fbe28dc3 100644
--- a/libheif/codecs/uncompressed/unc_decoder_component_interleave.h
+++ b/libheif/codecs/uncompressed/unc_decoder_component_interleave.h
@@ -31,10 +31,10 @@ class unc_decoder_component_interleave : public unc_decoder_legacybase
{
public:
unc_decoder_component_interleave(uint32_t width, uint32_t height,
- std::shared_ptr<const Box_cmpd> cmpd,
- std::shared_ptr<const Box_uncC> uncC,
+ const std::shared_ptr<const Box_cmpd>& cmpd,
+ const std::shared_ptr<const Box_uncC>& uncC,
const std::vector<uint32_t>& uncC_index_to_comp_ids) :
- unc_decoder_legacybase(width, height, std::move(cmpd), std::move(uncC), uncC_index_to_comp_ids) {}
+ unc_decoder_legacybase(width, height, cmpd, uncC, uncC_index_to_comp_ids) {}
Result<std::vector<uint64_t>> get_tile_data_sizes() const override;
diff --git a/libheif/codecs/uncompressed/unc_decoder_mixed_interleave.h b/libheif/codecs/uncompressed/unc_decoder_mixed_interleave.h
index f7eb56b3..0801f003 100644
--- a/libheif/codecs/uncompressed/unc_decoder_mixed_interleave.h
+++ b/libheif/codecs/uncompressed/unc_decoder_mixed_interleave.h
@@ -30,8 +30,8 @@
class unc_decoder_mixed_interleave : public unc_decoder_legacybase
{
public:
- unc_decoder_mixed_interleave(uint32_t width, uint32_t height, std::shared_ptr<const Box_cmpd> cmpd, std::shared_ptr<const Box_uncC> uncC, const std::vector<uint32_t>& uncC_index_to_comp_ids) :
- unc_decoder_legacybase(width, height, std::move(cmpd), std::move(uncC), uncC_index_to_comp_ids) {}
+ unc_decoder_mixed_interleave(uint32_t width, uint32_t height, const std::shared_ptr<const Box_cmpd>& cmpd, const std::shared_ptr<const Box_uncC>& uncC, const std::vector<uint32_t>& uncC_index_to_comp_ids) :
+ unc_decoder_legacybase(width, height, cmpd, uncC, uncC_index_to_comp_ids) {}
Result<std::vector<uint64_t>> get_tile_data_sizes() const override;
diff --git a/libheif/codecs/uncompressed/unc_decoder_pixel_interleave.h b/libheif/codecs/uncompressed/unc_decoder_pixel_interleave.h
index 833096cb..d4dd9679 100644
--- a/libheif/codecs/uncompressed/unc_decoder_pixel_interleave.h
+++ b/libheif/codecs/uncompressed/unc_decoder_pixel_interleave.h
@@ -30,8 +30,8 @@
class unc_decoder_pixel_interleave : public unc_decoder_legacybase
{
public:
- unc_decoder_pixel_interleave(uint32_t width, uint32_t height, std::shared_ptr<const Box_cmpd> cmpd, std::shared_ptr<const Box_uncC> uncC, const std::vector<uint32_t>& uncC_index_to_comp_ids) :
- unc_decoder_legacybase(width, height, std::move(cmpd), std::move(uncC), uncC_index_to_comp_ids) {}
+ unc_decoder_pixel_interleave(uint32_t width, uint32_t height, const std::shared_ptr<const Box_cmpd>& cmpd, const std::shared_ptr<const Box_uncC>& uncC, const std::vector<uint32_t>& uncC_index_to_comp_ids) :
+ unc_decoder_legacybase(width, height, cmpd, uncC, uncC_index_to_comp_ids) {}
Result<std::vector<uint64_t>> get_tile_data_sizes() const override;
diff --git a/libheif/codecs/uncompressed/unc_decoder_row_interleave.h b/libheif/codecs/uncompressed/unc_decoder_row_interleave.h
index fe85d4d7..a8db7aae 100644
--- a/libheif/codecs/uncompressed/unc_decoder_row_interleave.h
+++ b/libheif/codecs/uncompressed/unc_decoder_row_interleave.h
@@ -31,8 +31,8 @@ class unc_decoder_row_interleave : public unc_decoder_legacybase
{
public:
unc_decoder_row_interleave(uint32_t width, uint32_t height,
- std::shared_ptr<const Box_cmpd> cmpd, std::shared_ptr<const Box_uncC> uncC, const std::vector<uint32_t>& uncC_index_to_comp_ids) :
- unc_decoder_legacybase(width, height, std::move(cmpd), std::move(uncC), uncC_index_to_comp_ids) {}
+ const std::shared_ptr<const Box_cmpd>& cmpd, const std::shared_ptr<const Box_uncC>& uncC, const std::vector<uint32_t>& uncC_index_to_comp_ids) :
+ unc_decoder_legacybase(width, height, cmpd, uncC, uncC_index_to_comp_ids) {}
Result<std::vector<uint64_t>> get_tile_data_sizes() const override;
diff --git a/libheif/codecs/uncompressed/unc_enc.cc b/libheif/codecs/uncompressed/unc_enc.cc
index cde3a597..59230d78 100644
--- a/libheif/codecs/uncompressed/unc_enc.cc
+++ b/libheif/codecs/uncompressed/unc_enc.cc
@@ -63,7 +63,7 @@ std::shared_ptr<class Box_VisualSampleEntry> Encoder_uncompressed::get_sample_de
auto uncv = std::make_shared<Box_uncv>();
uncv->get_VisualSampleEntry().compressorname = "iso23001-17";
- for (auto prop : data.properties) {
+ for (const auto& prop : data.properties) {
switch (prop->get_short_type()) {
case fourcc("cmpd"):
case fourcc("uncC"):
diff --git a/libheif/codecs/vvc_enc.cc b/libheif/codecs/vvc_enc.cc
index 32495386..bb8d83a0 100644
--- a/libheif/codecs/vvc_enc.cc
+++ b/libheif/codecs/vvc_enc.cc
@@ -107,7 +107,7 @@ std::shared_ptr<class Box_VisualSampleEntry> Encoder_VVC::get_sample_description
auto vvc1 = std::make_shared<Box_vvc1>();
vvc1->get_VisualSampleEntry().compressorname = "VVC";
- for (auto prop : data.properties) {
+ for (const auto& prop : data.properties) {
if (prop->get_short_type() == fourcc("vvcC")) {
vvc1->append_child_box(prop);
return vvc1;
diff --git a/libheif/color-conversion/colorconversion.h b/libheif/color-conversion/colorconversion.h
index 3569e83c..54e94e0d 100644
--- a/libheif/color-conversion/colorconversion.h
+++ b/libheif/color-conversion/colorconversion.h
@@ -67,7 +67,7 @@ enum SpeedCosts
struct ColorStateWithCost
{
- ColorStateWithCost(ColorState c, int s) : color_state(std::move(c)), speed_costs(s) {}
+ ColorStateWithCost(ColorState c, int s) : color_state(c), speed_costs(s) {}
ColorState color_state;
diff --git a/libheif/context.cc b/libheif/context.cc
index 110a5588..9c6d7883 100644
--- a/libheif/context.cc
+++ b/libheif/context.cc
@@ -1940,7 +1940,7 @@ Error HeifContext::add_generic_metadata(const std::shared_ptr<ImageItem>& master
}
-heif_property_id HeifContext::add_property(heif_item_id targetItem, std::shared_ptr<Box> property, bool essential)
+heif_property_id HeifContext::add_property(heif_item_id targetItem, const std::shared_ptr<Box>& property, bool essential)
{
heif_property_id id;
@@ -2113,6 +2113,7 @@ Error HeifContext::interpret_heif_file_sequences()
// --- post-parsing initialization
std::vector<std::shared_ptr<Track>> all_tracks;
+ all_tracks.reserve(m_tracks.size());
for (auto& track : m_tracks) {
all_tracks.push_back(track.second);
}
@@ -2132,6 +2133,7 @@ std::vector<uint32_t> HeifContext::get_track_IDs() const
{
std::vector<uint32_t> ids;
+ ids.reserve(m_tracks.size());
for (const auto& track : m_tracks) {
ids.push_back(track.first);
}
@@ -2255,7 +2257,7 @@ Result<std::shared_ptr<Track_Visual>> HeifContext::add_visual_sequence_track(con
Result<std::shared_ptr<class Track_Metadata>> HeifContext::add_uri_metadata_sequence_track(const TrackOptions* options,
- std::string uri)
+ const std::string& uri)
{
m_heif_file->init_for_sequence();
diff --git a/libheif/context.h b/libheif/context.h
index 27f3a3c1..8e562be2 100644
--- a/libheif/context.h
+++ b/libheif/context.h
@@ -175,7 +175,7 @@ public:
uint32_t item_type, const char* content_type, const char* item_uri_type,
heif_metadata_compression compression, heif_item_id* out_item_id);
- heif_property_id add_property(heif_item_id targetItem, std::shared_ptr<Box> property, bool essential);
+ heif_property_id add_property(heif_item_id targetItem, const std::shared_ptr<Box>& property, bool essential);
Result<heif_item_id> add_pyramid_group(const std::vector<heif_item_id>& layers);
@@ -232,7 +232,7 @@ public:
Result<std::shared_ptr<class Track_Visual>> add_visual_sequence_track(const TrackOptions*, uint32_t handler_type,
uint16_t width, uint16_t height);
- Result<std::shared_ptr<class Track_Metadata>> add_uri_metadata_sequence_track(const TrackOptions*, std::string uri);
+ Result<std::shared_ptr<class Track_Metadata>> add_uri_metadata_sequence_track(const TrackOptions*, const std::string& uri);
void add_text_item(std::shared_ptr<TextItem> text_item)
{
diff --git a/libheif/file.cc b/libheif/file.cc
index 194f6a3c..a0a10dc2 100644
--- a/libheif/file.cc
+++ b/libheif/file.cc
@@ -73,6 +73,7 @@ std::vector<heif_item_id> HeifFile::get_item_IDs() const
{
std::vector<heif_item_id> IDs;
+ IDs.reserve(m_infe_boxes.size());
for (const auto& infe : m_infe_boxes) {
IDs.push_back(infe.second->get_item_ID());
}
@@ -1224,7 +1225,7 @@ Result<heif_item_id> HeifFile::add_infe_mime(const char* content_type, heif_meta
}
-Result<heif_item_id> HeifFile::add_precompressed_infe_mime(const char* content_type, std::string content_encoding, const uint8_t* data, size_t size)
+Result<heif_item_id> HeifFile::add_precompressed_infe_mime(const char* content_type, const std::string& content_encoding, const uint8_t* data, size_t size)
{
// create an infe box describing what kind of data we are storing (this also creates a new ID)
@@ -1238,7 +1239,7 @@ Result<heif_item_id> HeifFile::add_precompressed_infe_mime(const char* content_t
heif_item_id metadata_id = infe_box->get_item_ID();
- set_precompressed_item_data(infe_box, data, size, std::move(content_encoding));
+ set_precompressed_item_data(infe_box, data, size, content_encoding);
return metadata_id;
}
@@ -1324,7 +1325,7 @@ Error HeifFile::set_item_data(const std::shared_ptr<Box_infe>& item, const uint8
}
-Error HeifFile::set_precompressed_item_data(const std::shared_ptr<Box_infe>& item, const uint8_t* data, size_t size, std::string content_encoding)
+Error HeifFile::set_precompressed_item_data(const std::shared_ptr<Box_infe>& item, const uint8_t* data, size_t size, const std::string& content_encoding)
{
// only set metadata compression for MIME type data which has 'content_encoding' field
if (!content_encoding.empty() &&
@@ -1370,28 +1371,28 @@ void HeifFile::set_primary_item_id(heif_item_id id)
}
-void HeifFile::set_ipco_box(std::shared_ptr<Box_ipco> ipco)
+void HeifFile::set_ipco_box(const std::shared_ptr<Box_ipco>& ipco)
{
m_ipco_box = ipco;
m_meta_box->replace_child_box(ipco);
}
-void HeifFile::set_ipma_box(std::shared_ptr<Box_ipma> ipma)
+void HeifFile::set_ipma_box(const std::shared_ptr<Box_ipma>& ipma)
{
m_ipma_box = ipma;
m_meta_box->replace_child_box(ipma);
}
-void HeifFile::set_iloc_box(std::shared_ptr<Box_iloc> iloc)
+void HeifFile::set_iloc_box(const std::shared_ptr<Box_iloc>& iloc)
{
m_iloc_box = iloc;
m_meta_box->replace_child_box(iloc);
}
-void HeifFile::set_iref_box(std::shared_ptr<Box_iref> iref)
+void HeifFile::set_iref_box(const std::shared_ptr<Box_iref>& iref)
{
m_iref_box = iref;
m_meta_box->replace_child_box(iref);
diff --git a/libheif/file.h b/libheif/file.h
index 2f9134e6..06de7253 100644
--- a/libheif/file.h
+++ b/libheif/file.h
@@ -141,7 +141,7 @@ public:
std::shared_ptr<Box_infe> get_infe_box(heif_item_id imageID);
- void set_iref_box(std::shared_ptr<Box_iref>);
+ void set_iref_box(const std::shared_ptr<Box_iref>&);
std::shared_ptr<Box_iref> get_iref_box() { return m_iref_box; }
@@ -149,11 +149,11 @@ public:
std::shared_ptr<Box_ipco> get_ipco_box() { return m_ipco_box; }
- void set_ipco_box(std::shared_ptr<Box_ipco>);
+ void set_ipco_box(const std::shared_ptr<Box_ipco>&);
std::shared_ptr<Box_ipco> get_ipco_box() const { return m_ipco_box; }
- void set_ipma_box(std::shared_ptr<Box_ipma>);
+ void set_ipma_box(const std::shared_ptr<Box_ipma>&);
std::shared_ptr<Box_ipma> get_ipma_box() { return m_ipma_box; }
@@ -221,19 +221,19 @@ public:
Result<heif_item_id> add_infe_mime(const char* content_type, heif_metadata_compression content_encoding, const uint8_t* data, size_t size);
- Result<heif_item_id> add_precompressed_infe_mime(const char* content_type, std::string content_encoding, const uint8_t* data, size_t size);
+ Result<heif_item_id> add_precompressed_infe_mime(const char* content_type, const std::string& content_encoding, const uint8_t* data, size_t size);
Result<heif_item_id> add_infe_uri(const char* item_uri_type, const uint8_t* data, size_t size);
Error set_item_data(const std::shared_ptr<Box_infe>& item, const uint8_t* data, size_t size, heif_metadata_compression compression);
- Error set_precompressed_item_data(const std::shared_ptr<Box_infe>& item, const uint8_t* data, size_t size, std::string content_encoding);
+ Error set_precompressed_item_data(const std::shared_ptr<Box_infe>& item, const uint8_t* data, size_t size, const std::string& content_encoding);
void append_iloc_data(heif_item_id id, const std::vector<uint8_t>& nal_packets, uint8_t construction_method);
void replace_iloc_data(heif_item_id id, uint64_t offset, const std::vector<uint8_t>& data, uint8_t construction_method = 0);
- void set_iloc_box(std::shared_ptr<Box_iloc>);
+ void set_iloc_box(const std::shared_ptr<Box_iloc>&);
std::shared_ptr<Box_iloc> get_iloc_box() { return m_iloc_box; }
diff --git a/libheif/image-items/grid.cc b/libheif/image-items/grid.cc
index 989f28b5..06f8c997 100644
--- a/libheif/image-items/grid.cc
+++ b/libheif/image-items/grid.cc
@@ -27,6 +27,7 @@
#include <mutex>
#include <set>
#include <algorithm>
+#include <utility>
#include "api_structs.h"
#include "security_limits.h"
@@ -247,7 +248,7 @@ static void wait_for_jobs(std::deque<std::future<Error> >* jobs) {
}
#endif
-Result<std::shared_ptr<HeifPixelImage>> ImageItem_Grid::decode_full_grid_image(const heif_decoding_options& options, DecodeTraversalState decode_state) const
+Result<std::shared_ptr<HeifPixelImage>> ImageItem_Grid::decode_full_grid_image(const heif_decoding_options& options, const DecodeTraversalState& decode_state) const
{
std::shared_ptr<HeifPixelImage> img; // the decoded image
@@ -483,7 +484,7 @@ Error ImageItem_Grid::decode_and_paste_tile_image(heif_item_id tileID, uint32_t
std::shared_ptr<HeifPixelImage>& inout_image,
const heif_decoding_options& options,
int& progress_counter,
- std::shared_ptr<std::vector<Error> > warnings,
+ const std::shared_ptr<std::vector<Error> >& warnings,
DecodeTraversalState decode_state) const
{
std::shared_ptr<HeifPixelImage> tile_img;
@@ -510,7 +511,7 @@ Error ImageItem_Grid::decode_and_paste_tile_image(heif_item_id tileID, uint32_t
return error;
}
- auto decodeResult = tileItem->decode_image(options, false, 0, 0, decode_state);
+ auto decodeResult = tileItem->decode_image(options, false, 0, 0, std::move(decode_state));
if (!decodeResult) {
if (!options.strict_decoding) {
// We ignore broken tiles. The un-pasted canvas region stays zero from calloc().
@@ -599,7 +600,7 @@ Result<std::shared_ptr<HeifPixelImage>> ImageItem_Grid::decode_grid_tile(const h
return error;
}
- return tile_item->decode_compressed_image(options, false, 0, 0, decode_state);
+ return tile_item->decode_compressed_image(options, false, 0, 0, std::move(decode_state));
}
diff --git a/libheif/image-items/grid.h b/libheif/image-items/grid.h
index 7cd6a27e..ec8bba50 100644
--- a/libheif/image-items/grid.h
+++ b/libheif/image-items/grid.h
@@ -166,14 +166,14 @@ private:
Error read_grid_spec();
- Result<std::shared_ptr<HeifPixelImage>> decode_full_grid_image(const heif_decoding_options& options, DecodeTraversalState decode_state) const;
+ Result<std::shared_ptr<HeifPixelImage>> decode_full_grid_image(const heif_decoding_options& options, const DecodeTraversalState& decode_state) const;
Result<std::shared_ptr<HeifPixelImage>> decode_grid_tile(const heif_decoding_options& options, uint32_t tx, uint32_t ty, DecodeTraversalState decode_state) const;
Error decode_and_paste_tile_image(heif_item_id tileID, uint32_t x0, uint32_t y0,
std::shared_ptr<HeifPixelImage>& inout_image,
const heif_decoding_options& options, int& progress_counter,
- std::shared_ptr<std::vector<Error> > warnings,
+ const std::shared_ptr<std::vector<Error> >& warnings,
DecodeTraversalState decode_state) const;
};
diff --git a/libheif/image-items/image_item.cc b/libheif/image-items/image_item.cc
index b40a0252..d5624bab 100644
--- a/libheif/image-items/image_item.cc
+++ b/libheif/image-items/image_item.cc
@@ -79,7 +79,7 @@ std::shared_ptr<HeifFile> ImageItem::get_file() const
}
-heif_property_id ImageItem::add_property(std::shared_ptr<Box> property, bool essential)
+heif_property_id ImageItem::add_property(const std::shared_ptr<Box>& property, bool essential)
{
if (!property) {
return 0;
@@ -91,7 +91,7 @@ heif_property_id ImageItem::add_property(std::shared_ptr<Box> property, bool ess
}
-heif_property_id ImageItem::add_property_without_deduplication(std::shared_ptr<Box> property, bool essential)
+heif_property_id ImageItem::add_property_without_deduplication(const std::shared_ptr<Box>& property, bool essential)
{
if (!property) {
return 0;
diff --git a/libheif/image-items/image_item.h b/libheif/image-items/image_item.h
index 960bebf4..2c1c7d71 100644
--- a/libheif/image-items/image_item.h
+++ b/libheif/image-items/image_item.h
@@ -26,6 +26,7 @@
#include "security_limits.h"
#include "nclx.h"
#include <string>
+#include <utility>
#include <vector>
#include <memory>
#include <mutex>
@@ -166,9 +167,9 @@ public:
return result;
}
- heif_property_id add_property(std::shared_ptr<Box> property, bool essential);
+ heif_property_id add_property(const std::shared_ptr<Box>& property, bool essential);
- heif_property_id add_property_without_deduplication(std::shared_ptr<Box> property, bool essential);
+ heif_property_id add_property_without_deduplication(const std::shared_ptr<Box>& property, bool essential);
void set_resolution(uint32_t w, uint32_t h)
{
@@ -532,7 +533,7 @@ public:
// dummy ImageItem class that is a placeholder for unsupported item types
ImageItem_Error(uint32_t item_type, heif_item_id id, Error err)
- : ImageItem(nullptr, id), m_item_type(item_type), m_item_error(err) {}
+ : ImageItem(nullptr, id), m_item_type(item_type), m_item_error(std::move(err)) {}
uint32_t get_infe_type() const override
{
diff --git a/libheif/image-items/tiled.cc b/libheif/image-items/tiled.cc
index 72bf7b0c..936b43b8 100644
--- a/libheif/image-items/tiled.cc
+++ b/libheif/image-items/tiled.cc
@@ -381,7 +381,7 @@ Error TiledHeader::read_full_offset_table(const std::shared_ptr<HeifFile>& file,
Error TiledHeader::read_offset_table_range(const std::shared_ptr<HeifFile>& file, heif_item_id tild_id,
uint64_t start, uint64_t end)
{
- const Error eofError(heif_error_Invalid_input,
+ Error eofError(heif_error_Invalid_input,
heif_suberror_Unspecified,
"Tili header data incomplete");
@@ -759,7 +759,7 @@ ImageItem_Tiled::add_new_tiled_item(HeifContext* ctx, const heif_tiled_image_par
const heif_encoding_options* encoding_options)
{
Result<uint64_t> num_tiles_result = number_of_tiles(*parameters, ctx->get_security_limits());
- if (auto err = num_tiles_result.error()) {
+ if (const auto& err = num_tiles_result.error()) {
return err;
}
diff --git a/libheif/plugins/decoder_aom.cc b/libheif/plugins/decoder_aom.cc
index 76b5004f..25ec3a10 100644
--- a/libheif/plugins/decoder_aom.cc
+++ b/libheif/plugins/decoder_aom.cc
@@ -324,7 +324,8 @@ heif_error aom_push_data2(void* decoder_raw, const void* frame_data, size_t fram
(void)ver;
aom_codec_err_t aomerr;
- aomerr = aom_codec_decode(&decoder->codec, (const uint8_t*) frame_data, frame_size, (void*)user_data);
+ // The codec hands this opaque pointer back unchanged; it carries an integer, not an address.
+ aomerr = aom_codec_decode(&decoder->codec, (const uint8_t*) frame_data, frame_size, (void*)user_data); // NOLINT(performance-no-int-to-ptr)
if (aomerr) {
heif_error err = {heif_error_Invalid_input, heif_suberror_Unspecified, aom_codec_err_to_string(aomerr)};
return err;
diff --git a/libheif/plugins/decoder_dav1d.cc b/libheif/plugins/decoder_dav1d.cc
index 31d5ed08..dfe9a18d 100644
--- a/libheif/plugins/decoder_dav1d.cc
+++ b/libheif/plugins/decoder_dav1d.cc
@@ -214,7 +214,8 @@ heif_error dav1d_push_data2(void* decoder_raw, const void* frame_data, size_t fr
memcpy(d, frame_data, frame_size);
- packet.m.user_data.data = (uint8_t*)user_data;
+ // The codec hands this opaque pointer back unchanged; it carries an integer, not an address.
+ packet.m.user_data.data = (uint8_t*)user_data; // NOLINT(performance-no-int-to-ptr)
// --- put data into queue
diff --git a/libheif/plugins/decoder_libde265.cc b/libheif/plugins/decoder_libde265.cc
index 4f78f4df..8a74160f 100644
--- a/libheif/plugins/decoder_libde265.cc
+++ b/libheif/plugins/decoder_libde265.cc
@@ -357,7 +357,8 @@ static heif_error libde265_v1_push_data2(void* decoder_raw, const void* data, si
printf("put nal with size %d %x\n", nal_size, *(cdata+ptr));
#endif
- de265_push_NAL(decoder->ctx, cdata + ptr, nal_size, 0, (void*)user_data);
+ // The codec hands this opaque pointer back unchanged; it carries an integer, not an address.
+ de265_push_NAL(decoder->ctx, cdata + ptr, nal_size, 0, (void*)user_data); // NOLINT(performance-no-int-to-ptr)
ptr += nal_size;
}
diff --git a/libheif/plugins/encoder_openjph.cc b/libheif/plugins/encoder_openjph.cc
index 58ac9c90..c9f3d24f 100644
--- a/libheif/plugins/encoder_openjph.cc
+++ b/libheif/plugins/encoder_openjph.cc
@@ -523,7 +523,7 @@ static const heif_error &ojph_set_codestream_comment(encoder_struct_ojph *encode
static const heif_error &ojph_set_tile_size(encoder_struct_ojph *encoder, const char *value)
{
std::string valueStr(value);
- size_t commaOffset = valueStr.find(",");
+ size_t commaOffset = valueStr.find(',');
if (commaOffset == std::string::npos) {
return heif_error_invalid_parameter_value;
}
@@ -594,7 +594,7 @@ static const int log_base_2(unsigned long v)
static const heif_error &ojph_set_block_dimensions(encoder_struct_ojph *encoder, const char *value)
{
std::string valueStr(value);
- size_t commaOffset = valueStr.find(",");
+ size_t commaOffset = valueStr.find(',');
if (commaOffset == std::string::npos) {
return heif_error_invalid_parameter_value;
}
diff --git a/libheif/plugins/encoder_x265.cc b/libheif/plugins/encoder_x265.cc
index 97cd6e0d..9ec1ae9a 100644
--- a/libheif/plugins/encoder_x265.cc
+++ b/libheif/plugins/encoder_x265.cc
@@ -1124,7 +1124,8 @@ static heif_error x265_encode_sequence_frame(void* encoder_raw, const heif_image
}
pic->bitDepth = encoder->bit_depth;
- pic->userData = reinterpret_cast<void*>(frame_nr);
+ // The codec hands this opaque pointer back unchanged; it carries an integer, not an address.
+ pic->userData = reinterpret_cast<void*>(frame_nr); // NOLINT(performance-no-int-to-ptr)
x265_nal* nals = nullptr;
uint32_t num_nals = 0;
diff --git a/libheif/region.cc b/libheif/region.cc
index 5ae3d5e4..ca49139e 100644
--- a/libheif/region.cc
+++ b/libheif/region.cc
@@ -514,7 +514,7 @@ void RegionGeometry_InlineMask::encode(StreamWriter& writer, int field_size_byte
}
-Result<RegionCoordinateTransform> RegionCoordinateTransform::create(std::shared_ptr<HeifFile> file,
+Result<RegionCoordinateTransform> RegionCoordinateTransform::create(const std::shared_ptr<HeifFile>& file,
heif_item_id item_id,
int reference_width, int reference_height)
{
diff --git a/libheif/region.h b/libheif/region.h
index c5b0ac0e..6e156843 100644
--- a/libheif/region.h
+++ b/libheif/region.h
@@ -190,7 +190,7 @@ class RegionCoordinateTransform
public:
// Fails if a transformative property of the image cannot be applied (e.g. a 'clap'
// on an image size outside the supported range).
- static Result<RegionCoordinateTransform> create(std::shared_ptr<HeifFile> file,
+ static Result<RegionCoordinateTransform> create(const std::shared_ptr<HeifFile>& file,
heif_item_id item_id,
int reference_width, int reference_height);
diff --git a/libheif/sequences/chunk.h b/libheif/sequences/chunk.h
index b788d861..8b05fa14 100644
--- a/libheif/sequences/chunk.h
+++ b/libheif/sequences/chunk.h
@@ -23,6 +23,7 @@
#include "codecs/decoder.h"
#include <memory>
+#include <utility>
#include <vector>
@@ -62,7 +63,7 @@ public:
DataExtent get_data_extent_for_sample(uint32_t n) const;
- void set_decoder(std::shared_ptr<class Decoder> dec) { m_decoder = dec; }
+ void set_decoder(std::shared_ptr<class Decoder> dec) { m_decoder = std::move(dec); }
private:
// Sets `success` to false if the chunk cannot be constructed validly
diff --git a/libheif/sequences/seq_boxes.h b/libheif/sequences/seq_boxes.h
index bd593c92..729ea2f4 100644
--- a/libheif/sequences/seq_boxes.h
+++ b/libheif/sequences/seq_boxes.h
@@ -26,6 +26,7 @@
#include <string>
#include <memory>
+#include <utility>
#include <vector>
#include <limits>
@@ -324,7 +325,7 @@ public:
}
}
- void add_sample_entry(std::shared_ptr<class Box> entry)
+ void add_sample_entry(const std::shared_ptr<class Box>& entry)
{
m_sample_entries.push_back(entry);
}
@@ -710,7 +711,7 @@ public:
set_short_type(fourcc("uri "));
}
- void set_uri(std::string uri) { m_uri = uri; }
+ void set_uri(std::string uri) { m_uri = std::move(uri); }
std::string get_uri() const { return m_uri; }
diff --git a/libheif/sequences/track.cc b/libheif/sequences/track.cc
index 04a3569f..016f1218 100644
--- a/libheif/sequences/track.cc
+++ b/libheif/sequences/track.cc
@@ -116,8 +116,8 @@ void SampleAuxInfoHelper::write_all(const std::shared_ptr<Box>& parent, const st
}
-SampleAuxInfoReader::SampleAuxInfoReader(std::shared_ptr<Box_saiz> saiz,
- std::shared_ptr<Box_saio> saio,
+SampleAuxInfoReader::SampleAuxInfoReader(const std::shared_ptr<Box_saiz>& saiz,
+ const std::shared_ptr<Box_saio>& saio,
const std::vector<std::shared_ptr<Chunk>>& chunks)
{
m_saiz = saiz;
@@ -949,7 +949,7 @@ void Track::add_chunk(heif_compression_format format)
m_stsc->add_chunk(chunkIdx);
}
-void Track::set_sample_description_box(std::shared_ptr<Box> sample_description_box)
+void Track::set_sample_description_box(const std::shared_ptr<Box>& sample_description_box)
{
// --- add 'taic' when we store timestamps as sample auxiliary information
@@ -1016,7 +1016,7 @@ Error Track::write_sample_data(const std::vector<uint8_t>& raw_data, uint32_t sa
if (m_track_info.with_sample_content_ids != heif_sample_aux_info_presence_none) {
if (gimi_contentID) {
- auto id = *gimi_contentID;
+ const auto& id = *gimi_contentID;
const char* id_str = id.c_str();
std::vector<uint8_t> id_vector;
id_vector.insert(id_vector.begin(), id_str, id_str + id.length() + 1);
diff --git a/libheif/sequences/track.h b/libheif/sequences/track.h
index 5da1fb94..524963f6 100644
--- a/libheif/sequences/track.h
+++ b/libheif/sequences/track.h
@@ -28,6 +28,7 @@
#include "libheif/heif_sequences.h"
#include <string>
#include <memory>
+#include <utility>
#include <vector>
class HeifContext;
@@ -67,8 +68,8 @@ private:
class SampleAuxInfoReader
{
public:
- SampleAuxInfoReader(std::shared_ptr<Box_saiz>,
- std::shared_ptr<Box_saio>,
+ SampleAuxInfoReader(const std::shared_ptr<Box_saiz>&,
+ const std::shared_ptr<Box_saio>&,
const std::vector<std::shared_ptr<Chunk>>& chunks);
heif_sample_aux_info_type get_type() const;
@@ -162,7 +163,7 @@ public:
void set_auxiliary_info_type(heif_auxiliary_track_info_type);
- void set_auxiliary_info_type_urn(std::string t) { m_auxiliary_info_type = t; }
+ void set_auxiliary_info_type_urn(std::string t) { m_auxiliary_info_type = std::move(t); }
bool is_visual_track() const;
@@ -292,7 +293,7 @@ protected:
// Has to be called when we call add_chunk().
// It is not merged with add_chunk() because the sample_description_box may need information from the
// first encoded frame.
- void set_sample_description_box(std::shared_ptr<Box> sample_description_box);
+ void set_sample_description_box(const std::shared_ptr<Box>& sample_description_box);
// Write the actual sample data. `tai` may be null and `gimi_contentID` may be empty.
// In these cases, no timestamp or no contentID will be written, respectively.
diff --git a/libheif/sequences/track_visual.cc b/libheif/sequences/track_visual.cc
index 60c98c1a..580ae064 100644
--- a/libheif/sequences/track_visual.cc
+++ b/libheif/sequences/track_visual.cc
@@ -102,7 +102,7 @@ Error Track_Visual::initialize_after_parsing(HeifContext* ctx, const std::vector
// Only assign to image-sequence tracks (TODO: are there also alpha tracks allowed for video tracks 'heif_track_type_video'?)
if (get_handler() == heif_track_type_image_sequence) {
- for (auto track : all_tracks) {
+ for (const auto& track : all_tracks) {
// skip ourselves
if (track->get_id() != get_id()) {
// Is this an aux alpha track?
@@ -395,7 +395,7 @@ Error Track_Visual::encode_end_of_sequence(heif_encoder* h_encoder)
}
-Error Track_Visual::encode_image(std::shared_ptr<HeifPixelImage> image,
+Error Track_Visual::encode_image(const std::shared_ptr<HeifPixelImage>& image,
heif_encoder* h_encoder,
const heif_sequence_encoding_options* in_options,
heif_image_input_class input_class)
diff --git a/libheif/sequences/track_visual.h b/libheif/sequences/track_visual.h
index 94890d4c..bb683089 100644
--- a/libheif/sequences/track_visual.h
+++ b/libheif/sequences/track_visual.h
@@ -52,7 +52,7 @@ public:
Result<std::shared_ptr<HeifPixelImage>> decode_next_image_sample(const heif_decoding_options& options);
- Error encode_image(std::shared_ptr<HeifPixelImage> image,
+ Error encode_image(const std::shared_ptr<HeifPixelImage>& image,
heif_encoder* encoder,
const heif_sequence_encoding_options* options,
heif_image_input_class image_class);