Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6c1e840

Browse files
committed
Use structured binding for tuples where possible
1 parent e1628d8 commit 6c1e840

File tree

2 files changed

+17
-22
lines changed

2 files changed

+17
-22
lines changed

src/metadata.cc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -219,10 +219,10 @@ class MetadataWorker : public Napi::AsyncWorker {
219219
if (!baton->levels.empty()) {
220220
int i = 0;
221221
Napi::Array levels = Napi::Array::New(env, static_cast<size_t>(baton->levels.size()));
222-
for (std::pair<int, int> const &l : baton->levels) {
222+
for (const auto& [width, height] : baton->levels) {
223223
Napi::Object level = Napi::Object::New(env);
224-
level.Set("width", l.first);
225-
level.Set("height", l.second);
224+
level.Set("width", width);
225+
level.Set("height", height);
226226
levels.Set(i++, level);
227227
}
228228
info.Set("levels", levels);
@@ -279,10 +279,10 @@ class MetadataWorker : public Napi::AsyncWorker {
279279
if (baton->comments.size() > 0) {
280280
int i = 0;
281281
Napi::Array comments = Napi::Array::New(env, baton->comments.size());
282-
for (auto &c : baton->comments) {
282+
for (const auto& [keyword, text] : baton->comments) {
283283
Napi::Object comment = Napi::Object::New(env);
284-
comment.Set("keyword", c.first);
285-
comment.Set("text", c.second);
284+
comment.Set("keyword", keyword);
285+
comment.Set("text", text);
286286
comments.Set(i++, comment);
287287
}
288288
info.Set("comments", comments);

src/pipeline.cc

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -455,12 +455,10 @@ class PipelineWorker : public Napi::AsyncWorker {
455455
std::tie(image, background) = sharp::ApplyAlpha(image, baton->resizeBackground, shouldPremultiplyAlpha);
456456

457457
// Embed
458-
int left;
459-
int top;
460-
std::tie(left, top) = sharp::CalculateEmbedPosition(
458+
const auto& [left, top] = sharp::CalculateEmbedPosition(
461459
inputWidth, inputHeight, baton->width, baton->height, baton->position);
462-
int width = std::max(inputWidth, baton->width);
463-
int height = std::max(inputHeight, baton->height);
460+
const int width = std::max(inputWidth, baton->width);
461+
const int height = std::max(inputHeight, baton->height);
464462

465463
image = nPages > 1
466464
? sharp::EmbedMultiPage(image,
@@ -479,13 +477,10 @@ class PipelineWorker : public Napi::AsyncWorker {
479477
// Crop
480478
if (baton->position < 9) {
481479
// Gravity-based crop
482-
int left;
483-
int top;
484-
485-
std::tie(left, top) = sharp::CalculateCrop(
480+
const auto& [left, top] = sharp::CalculateCrop(
486481
inputWidth, inputHeight, baton->width, baton->height, baton->position);
487-
int width = std::min(inputWidth, baton->width);
488-
int height = std::min(inputHeight, baton->height);
482+
const int width = std::min(inputWidth, baton->width);
483+
const int height = std::min(inputHeight, baton->height);
489484

490485
image = nPages > 1
491486
? sharp::CropMultiPage(image,
@@ -803,7 +798,7 @@ class PipelineWorker : public Napi::AsyncWorker {
803798
}
804799
if (image.interpretation() != baton->colourspace) {
805800
image = image.colourspace(baton->colourspace, VImage::option()->set("source_space", image.interpretation()));
806-
if (inputProfile.first && baton->withIccProfile.empty()) {
801+
if (inputProfile.first != nullptr && baton->withIccProfile.empty()) {
807802
image = sharp::SetProfile(image, inputProfile);
808803
}
809804
}
@@ -860,8 +855,8 @@ class PipelineWorker : public Napi::AsyncWorker {
860855
if (!baton->withExifMerge) {
861856
image = sharp::RemoveExif(image);
862857
}
863-
for (const auto& s : baton->withExif) {
864-
image.set(s.first.data(), s.second.data());
858+
for (const auto& [key, value] : baton->withExif) {
859+
image.set(key.c_str(), value.c_str());
865860
}
866861
}
867862
// XMP buffer
@@ -1440,11 +1435,11 @@ class PipelineWorker : public Napi::AsyncWorker {
14401435
std::string
14411436
AssembleSuffixString(std::string extname, std::vector<std::pair<std::string, std::string>> options) {
14421437
std::string argument;
1443-
for (auto const &option : options) {
1438+
for (const auto& [key, value] : options) {
14441439
if (!argument.empty()) {
14451440
argument += ",";
14461441
}
1447-
argument += option.first + "=" + option.second;
1442+
argument += key + "=" + value;
14481443
}
14491444
return extname + "[" + argument + "]";
14501445
}

0 commit comments

Comments
 (0)