Fixed return strict const iterator, replace to range-based loop C++17 and code refactor

Signed-off-by: Herman Semenov <GermanAizek@yandex.ru>
This commit is contained in:
Semenov German 2024-08-24 13:30:29 +03:00 committed by Herman Semenov
parent fda2fdae69
commit 6d420eed86
8 changed files with 31 additions and 32 deletions

View File

@ -54,7 +54,7 @@ public:
for (auto it = wait_list.begin(); it != wait_list.end();) { for (auto it = wait_list.begin(); it != wait_list.end();) {
auto& waiter = *it; auto& waiter = *it;
if (waiter.need_count > token_count) { if (waiter.need_count > token_count) {
it++; ++it;
continue; continue;
} }
it = wait_list.erase(it); it = wait_list.erase(it);
@ -141,7 +141,7 @@ public:
// Find the first with priority less then us and insert right before it. // Find the first with priority less then us and insert right before it.
auto it = wait_list.begin(); auto it = wait_list.begin();
while (it != wait_list.end() && it->priority > waiter.priority) { while (it != wait_list.end() && it->priority > waiter.priority) {
it++; ++it;
} }
wait_list.insert(it, waiter); wait_list.insert(it, waiter);
} }

View File

@ -45,7 +45,7 @@ PAddr MemoryManager::Allocate(PAddr search_start, PAddr search_end, size_t size,
return dmem_area->second.is_free && dmem_area->second.size >= size; return dmem_area->second.is_free && dmem_area->second.size >= size;
}; };
while (!is_suitable() && dmem_area->second.GetEnd() <= search_end) { while (!is_suitable() && dmem_area->second.GetEnd() <= search_end) {
dmem_area++; ++dmem_area;
} }
ASSERT_MSG(is_suitable(), "Unable to find free direct memory area"); ASSERT_MSG(is_suitable(), "Unable to find free direct memory area");
@ -275,7 +275,7 @@ int MemoryManager::VirtualQuery(VAddr addr, int flags,
auto it = FindVMA(addr); auto it = FindVMA(addr);
if (it->second.type == VMAType::Free && flags == 1) { if (it->second.type == VMAType::Free && flags == 1) {
it++; ++it;
} }
if (it->second.type == VMAType::Free) { if (it->second.type == VMAType::Free) {
LOG_WARNING(Kernel_Vmm, "VirtualQuery on free memory region"); LOG_WARNING(Kernel_Vmm, "VirtualQuery on free memory region");
@ -376,7 +376,7 @@ VAddr MemoryManager::SearchFree(VAddr virtual_addr, size_t size, u32 alignment)
return remaining_size >= size; return remaining_size >= size;
}; };
while (!is_suitable()) { while (!is_suitable()) {
it++; ++it;
} }
return virtual_addr; return virtual_addr;
} }

View File

@ -149,10 +149,10 @@ void CFG::EmitDivergenceLabels() {
} }
void CFG::EmitBlocks() { void CFG::EmitBlocks() {
for (auto it = labels.begin(); it != labels.end(); it++) { for (auto it = labels.cbegin(); it != labels.cend(); ++it) {
const Label start = *it; const Label start = *it;
const auto next_it = std::next(it); const auto next_it = std::next(it);
const bool is_last = next_it == labels.end(); const bool is_last = (next_it == labels.cend());
if (is_last) { if (is_last) {
// Last label is special. // Last label is special.
return; return;
@ -179,7 +179,7 @@ void CFG::EmitBlocks() {
void CFG::LinkBlocks() { void CFG::LinkBlocks() {
const auto get_block = [this](u32 address) { const auto get_block = [this](u32 address) {
auto it = blocks.find(address, Compare{}); auto it = blocks.find(address, Compare{});
ASSERT_MSG(it != blocks.end() && it->begin == address); ASSERT_MSG(it != blocks.cend() && it->begin == address);
return &*it; return &*it;
}; };

View File

@ -143,32 +143,32 @@ std::string DumpExpr(const Statement* stmt) {
[[maybe_unused]] std::string DumpTree(const Tree& tree, u32 indentation = 0) { [[maybe_unused]] std::string DumpTree(const Tree& tree, u32 indentation = 0) {
std::string ret; std::string ret;
std::string indent(indentation, ' '); std::string indent(indentation, ' ');
for (auto stmt = tree.begin(); stmt != tree.end(); ++stmt) { for (const auto& stmt : tree) {
switch (stmt->type) { switch (stmt.type) {
case StatementType::Code: case StatementType::Code:
ret += fmt::format("{} Block {:04x} -> {:04x} (0x{:016x});\n", indent, ret += fmt::format("{} Block {:04x} -> {:04x} (0x{:016x});\n", indent,
stmt->block->begin, stmt->block->end, stmt.block->begin, stmt.block->end,
reinterpret_cast<uintptr_t>(stmt->block)); reinterpret_cast<uintptr_t>(stmt.block));
break; break;
case StatementType::Goto: case StatementType::Goto:
ret += fmt::format("{} if ({}) goto L{};\n", indent, DumpExpr(stmt->cond), ret += fmt::format("{} if ({}) goto L{};\n", indent, DumpExpr(stmt.cond),
stmt->label->id); stmt.label->id);
break; break;
case StatementType::Label: case StatementType::Label:
ret += fmt::format("{}L{}:\n", indent, stmt->id); ret += fmt::format("{}L{}:\n", indent, stmt.id);
break; break;
case StatementType::If: case StatementType::If:
ret += fmt::format("{} if ({}) {{\n", indent, DumpExpr(stmt->cond)); ret += fmt::format("{} if ({}) {{\n", indent, DumpExpr(stmt.cond));
ret += DumpTree(stmt->children, indentation + 4); ret += DumpTree(stmt.children, indentation + 4);
ret += fmt::format("{} }}\n", indent); ret += fmt::format("{} }}\n", indent);
break; break;
case StatementType::Loop: case StatementType::Loop:
ret += fmt::format("{} do {{\n", indent); ret += fmt::format("{} do {{\n", indent);
ret += DumpTree(stmt->children, indentation + 4); ret += DumpTree(stmt.children, indentation + 4);
ret += fmt::format("{} }} while ({});\n", indent, DumpExpr(stmt->cond)); ret += fmt::format("{} }} while ({});\n", indent, DumpExpr(stmt.cond));
break; break;
case StatementType::Break: case StatementType::Break:
ret += fmt::format("{} if ({}) break;\n", indent, DumpExpr(stmt->cond)); ret += fmt::format("{} if ({}) break;\n", indent, DumpExpr(stmt.cond));
break; break;
case StatementType::Return: case StatementType::Return:
ret += fmt::format("{} return;\n", indent); ret += fmt::format("{} return;\n", indent);
@ -180,7 +180,7 @@ std::string DumpExpr(const Statement* stmt) {
ret += fmt::format("{} unreachable;\n", indent); ret += fmt::format("{} unreachable;\n", indent);
break; break;
case StatementType::SetVariable: case StatementType::SetVariable:
ret += fmt::format("{} goto_L{} = {};\n", indent, stmt->id, DumpExpr(stmt->op)); ret += fmt::format("{} goto_L{} = {};\n", indent, stmt.id, DumpExpr(stmt.op));
break; break;
case StatementType::Function: case StatementType::Function:
case StatementType::Identity: case StatementType::Identity:
@ -623,8 +623,8 @@ private:
node.data.block = current_block; node.data.block = current_block;
}}; }};
Tree& tree{parent.children}; Tree& tree{parent.children};
for (auto it = tree.begin(); it != tree.end(); ++it) { for (auto& child : tree) {
Statement& stmt{*it}; Statement& stmt{child};
switch (stmt.type) { switch (stmt.type) {
case StatementType::Label: case StatementType::Label:
// Labels can be ignored // Labels can be ignored

View File

@ -109,13 +109,13 @@ public:
return instructions.begin(); return instructions.begin();
} }
[[nodiscard]] const_iterator begin() const { [[nodiscard]] const_iterator begin() const {
return instructions.begin(); return instructions.cbegin();
} }
[[nodiscard]] iterator end() { [[nodiscard]] iterator end() {
return instructions.end(); return instructions.end();
} }
[[nodiscard]] const_iterator end() const { [[nodiscard]] const_iterator end() const {
return instructions.end(); return instructions.cend();
} }
[[nodiscard]] reverse_iterator rbegin() { [[nodiscard]] reverse_iterator rbegin() {

View File

@ -43,11 +43,10 @@ struct RangeSet {
if (m_ranges_set.empty()) { if (m_ranges_set.empty()) {
return; return;
} }
auto it = m_ranges_set.begin();
auto end_it = m_ranges_set.end(); for (const auto& set : m_ranges_set) {
for (; it != end_it; it++) { const VAddr inter_addr_end = set.upper();
const VAddr inter_addr_end = it->upper(); const VAddr inter_addr = set.lower();
const VAddr inter_addr = it->lower();
func(inter_addr, inter_addr_end); func(inter_addr, inter_addr_end);
} }
} }

View File

@ -69,7 +69,7 @@ public:
bool IsVideoOutSurface(const AmdGpu::Liverpool::ColorBuffer& color_buffer) { bool IsVideoOutSurface(const AmdGpu::Liverpool::ColorBuffer& color_buffer) {
return std::ranges::find_if(vo_buffers_addr, [&](VAddr vo_buffer) { return std::ranges::find_if(vo_buffers_addr, [&](VAddr vo_buffer) {
return vo_buffer == color_buffer.Address(); return vo_buffer == color_buffer.Address();
}) != vo_buffers_addr.end(); }) != vo_buffers_addr.cend();
} }
bool ShowSplash(Frame* frame = nullptr); bool ShowSplash(Frame* frame = nullptr);

View File

@ -43,7 +43,7 @@ void Swapchain::Create(u32 width_, u32 height_, vk::SurfaceKHR surface_) {
std::find_if(modes.begin(), modes.end(), std::find_if(modes.begin(), modes.end(),
[&requested](vk::PresentModeKHR mode) { return mode == requested; }); [&requested](vk::PresentModeKHR mode) { return mode == requested; });
return it != modes.end(); return it != modes.cend();
}; };
const bool has_mailbox = find_mode(vk::PresentModeKHR::eMailbox); const bool has_mailbox = find_mode(vk::PresentModeKHR::eMailbox);