Skip to content

Commit 6a5d6ff

Browse files
committed
cosmetics
1 parent 110912f commit 6a5d6ff

File tree

8 files changed

+32
-36
lines changed

8 files changed

+32
-36
lines changed

llvmexpr/analysis/passes/PropWriteTypeSafetyPass.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,19 +44,20 @@ PropWriteTypeSafetyPass::run(const std::vector<Token>& tokens,
4444

4545
auto it = prop_types.find(prop_name);
4646
if (it != prop_types.end()) {
47-
auto& [stored_type, stored_idx] = it->second;
47+
auto& stored_type = it->second.first;
4848
if (stored_type != prop_type) {
4949
// DELETE can co-exist with other types.
5050
if (stored_type == PropWriteType::Delete) {
5151
stored_type = prop_type;
52-
stored_idx = static_cast<int>(i);
52+
it->second.second = static_cast<int>(i);
5353
} else if (prop_type != PropWriteType::Delete) {
5454
throw AnalysisError(
5555
std::format(
5656
"Inconsistent types used for property '{}'. "
5757
"Previous type: {} (idx: {}), current type: {} "
5858
"(idx: {}).",
59-
prop_name, enum_name(stored_type), stored_idx,
59+
prop_name, enum_name(stored_type),
60+
it->second.second,
6061
enum_name(prop_type), static_cast<int>(i)),
6162
static_cast<int>(i));
6263
}

llvmexpr/analysis/passes/StructurizeCFGPass.cpp

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -310,11 +310,8 @@ bool node_split_make_reducible(std::vector<CFGBlock>& cfg,
310310
if (in_component[(size_t)p] != 0) {
311311
continue; // keep SCC-internal edges pointing to original
312312
}
313-
for (int& s : cfg[(size_t)p].successors) {
314-
if (s == entry) {
315-
s = entry_clone;
316-
}
317-
}
313+
std::ranges::replace(cfg[(size_t)p].successors, entry,
314+
entry_clone);
318315
}
319316
}
320317

@@ -400,11 +397,7 @@ bool tail_duplicate_trivial_joins(std::vector<CFGBlock>& cfg,
400397
cfg.push_back(std::move(clone));
401398
origin_map.push_back(origin_map[(size_t)c]);
402399

403-
for (int& s : cfg[(size_t)p].successors) {
404-
if (s == c) {
405-
s = clone_idx;
406-
}
407-
}
400+
std::ranges::replace(cfg[(size_t)p].successors, c, clone_idx);
408401
}
409402

410403
changed = true;

llvmexpr/codegen/glsl/GLSLGenerator.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -647,12 +647,13 @@ bool GLSLGenerator::canStructureFrom(int start_block, int stop_block,
647647
}
648648
[[nodiscard]] bool handleNonlocalEdge(int /*block*/, int next,
649649
int stop_block,
650-
LoopContext& ctx) const {
650+
const LoopContext& ctx) const {
651651
auto saved = ctx;
652652
return gen->canEdgeToBlock(next, stop_block, saved);
653653
}
654-
bool handleBranch(int /*block*/, int t, int f, int join,
655-
int /*stop_block*/, LoopContext& ctx) const {
654+
[[nodiscard]] bool handleBranch(int /*block*/, int t, int f, int join,
655+
int /*stop_block*/,
656+
const LoopContext& ctx) const {
656657
auto saved_t = ctx;
657658
auto saved_f = ctx;
658659
return gen->canEdgeToBlock(t, join, saved_t) &&

llvmexpr/frontend/Tokenizer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ template <std::size_t N> struct FixedString {
7575
std::array<char, N> value;
7676

7777
// NOLINTNEXTLINE(modernize-avoid-c-arrays,cppcoreguidelines-avoid-c-arrays)
78-
constexpr FixedString(const char (&str)[N]) {
78+
explicit constexpr FixedString(const char (&str)[N]) {
7979
std::ranges::copy(str, value.begin());
8080
}
8181

llvmexpr/frontend/infix2postfix/PostfixBuilder.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
#include <cctype>
2323
#include <format>
24+
#include <numeric>
2425
#include <sstream>
2526

2627
namespace infix2postfix {
@@ -236,10 +237,11 @@ std::string PostfixBuilder::get_expression() const {
236237
return "";
237238
}
238239

239-
size_t total_len = 0;
240-
for (const auto& token : tokens) {
241-
total_len += token.length();
242-
}
240+
size_t total_len =
241+
std::accumulate(tokens.begin(), tokens.end(), size_t{0},
242+
[](size_t sum, const std::string& token) {
243+
return sum + token.length();
244+
});
243245
total_len += tokens.size() - 1; // for spaces
244246

245247
std::string result;

llvmexpr/frontend/infix2postfix/SemanticAnalyzer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -570,11 +570,11 @@ Type SemanticAnalyzer::analyze(CallExpr& expr) {
570570

571571
auto it = written_properties.find(prop_name);
572572
if (it != written_properties.end()) {
573-
auto& [stored_suffix, stored_range] = it->second;
573+
auto& stored_suffix = it->second.first;
574574
if (stored_suffix != suffix) {
575575
if (stored_suffix == "d") {
576576
stored_suffix = suffix;
577-
stored_range = expr.range;
577+
it->second.second = expr.range;
578578
} else if (suffix != "d") {
579579
reportError(
580580
std::format("Property '{}' is written with "

llvmexpr/runtime/vulkan/VulkanComputePipeline.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "VulkanContext.hpp"
2222
#include "VulkanMemory.hpp"
2323

24+
#include <algorithm>
2425
#include <memory>
2526
#include <mutex>
2627
#include <shaderc/shaderc.hpp>
@@ -220,10 +221,9 @@ void VulkanComputePipeline::updateDescriptorSets(
220221

221222
// Update cache
222223
cached_input_buffers.clear();
223-
cached_input_buffers.reserve(input_buffers.size());
224-
for (auto* buf : input_buffers) {
225-
cached_input_buffers.push_back(buf->buffer);
226-
}
224+
cached_input_buffers.resize(input_buffers.size());
225+
std::ranges::transform(input_buffers, cached_input_buffers.begin(),
226+
[](const auto* buf) { return buf->buffer; });
227227
cached_output_buffer = output_buffer.buffer;
228228
cached_props_buffer = new_props_buffer_handle;
229229

llvmexpr/runtime/vulkan/VulkanContext.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -206,10 +206,8 @@ void VulkanContext::pickPhysicalDevice() {
206206
return;
207207
}
208208

209-
for (const auto& dev : devices) {
210-
if (select_device(dev)) {
211-
return;
212-
}
209+
if (std::ranges::any_of(devices, select_device)) {
210+
return;
213211
}
214212

215213
throw std::runtime_error(std::format(
@@ -226,11 +224,12 @@ void VulkanContext::createDevice() {
226224

227225
std::vector<vk::ExtensionProperties> available_extensions =
228226
physical_device.enumerateDeviceExtensionProperties();
229-
for (const auto& ext : available_extensions) {
230-
if (strcmp(ext.extensionName, "VK_KHR_portability_subset") == 0) {
231-
device_extensions.push_back("VK_KHR_portability_subset");
232-
break;
233-
}
227+
const bool has_portability_subset = std::ranges::any_of(
228+
available_extensions, [](const vk::ExtensionProperties& ext) {
229+
return strcmp(ext.extensionName, "VK_KHR_portability_subset") == 0;
230+
});
231+
if (has_portability_subset) {
232+
device_extensions.push_back("VK_KHR_portability_subset");
234233
}
235234

236235
vk::DeviceCreateInfo create_info({}, queue_create_info,

0 commit comments

Comments
 (0)