Use structured binding for tuples where possible

This commit is contained in:
Lovell Fuller 2025-11-05 15:30:52 +00:00
parent e1628d8ef5
commit 6c1e840098
No known key found for this signature in database
GPG Key ID: 26C1635893ACB81F
2 changed files with 17 additions and 22 deletions

View File

@ -219,10 +219,10 @@ class MetadataWorker : public Napi::AsyncWorker {
if (!baton->levels.empty()) {
int i = 0;
Napi::Array levels = Napi::Array::New(env, static_cast<size_t>(baton->levels.size()));
for (std::pair<int, int> const &l : baton->levels) {
for (const auto& [width, height] : baton->levels) {
Napi::Object level = Napi::Object::New(env);
level.Set("width", l.first);
level.Set("height", l.second);
level.Set("width", width);
level.Set("height", height);
levels.Set(i++, level);
}
info.Set("levels", levels);
@ -279,10 +279,10 @@ class MetadataWorker : public Napi::AsyncWorker {
if (baton->comments.size() > 0) {
int i = 0;
Napi::Array comments = Napi::Array::New(env, baton->comments.size());
for (auto &c : baton->comments) {
for (const auto& [keyword, text] : baton->comments) {
Napi::Object comment = Napi::Object::New(env);
comment.Set("keyword", c.first);
comment.Set("text", c.second);
comment.Set("keyword", keyword);
comment.Set("text", text);
comments.Set(i++, comment);
}
info.Set("comments", comments);

View File

@ -455,12 +455,10 @@ class PipelineWorker : public Napi::AsyncWorker {
std::tie(image, background) = sharp::ApplyAlpha(image, baton->resizeBackground, shouldPremultiplyAlpha);
// Embed
int left;
int top;
std::tie(left, top) = sharp::CalculateEmbedPosition(
const auto& [left, top] = sharp::CalculateEmbedPosition(
inputWidth, inputHeight, baton->width, baton->height, baton->position);
int width = std::max(inputWidth, baton->width);
int height = std::max(inputHeight, baton->height);
const int width = std::max(inputWidth, baton->width);
const int height = std::max(inputHeight, baton->height);
image = nPages > 1
? sharp::EmbedMultiPage(image,
@ -479,13 +477,10 @@ class PipelineWorker : public Napi::AsyncWorker {
// Crop
if (baton->position < 9) {
// Gravity-based crop
int left;
int top;
std::tie(left, top) = sharp::CalculateCrop(
const auto& [left, top] = sharp::CalculateCrop(
inputWidth, inputHeight, baton->width, baton->height, baton->position);
int width = std::min(inputWidth, baton->width);
int height = std::min(inputHeight, baton->height);
const int width = std::min(inputWidth, baton->width);
const int height = std::min(inputHeight, baton->height);
image = nPages > 1
? sharp::CropMultiPage(image,
@ -803,7 +798,7 @@ class PipelineWorker : public Napi::AsyncWorker {
}
if (image.interpretation() != baton->colourspace) {
image = image.colourspace(baton->colourspace, VImage::option()->set("source_space", image.interpretation()));
if (inputProfile.first && baton->withIccProfile.empty()) {
if (inputProfile.first != nullptr && baton->withIccProfile.empty()) {
image = sharp::SetProfile(image, inputProfile);
}
}
@ -860,8 +855,8 @@ class PipelineWorker : public Napi::AsyncWorker {
if (!baton->withExifMerge) {
image = sharp::RemoveExif(image);
}
for (const auto& s : baton->withExif) {
image.set(s.first.data(), s.second.data());
for (const auto& [key, value] : baton->withExif) {
image.set(key.c_str(), value.c_str());
}
}
// XMP buffer
@ -1440,11 +1435,11 @@ class PipelineWorker : public Napi::AsyncWorker {
std::string
AssembleSuffixString(std::string extname, std::vector<std::pair<std::string, std::string>> options) {
std::string argument;
for (auto const &option : options) {
for (const auto& [key, value] : options) {
if (!argument.empty()) {
argument += ",";
}
argument += option.first + "=" + option.second;
argument += key + "=" + value;
}
return extname + "[" + argument + "]";
}