Move many loops over glcr::Vector to range-based loops.

This commit is contained in:
Drew Galbraith 2024-01-11 17:13:35 -08:00
parent c06d1741f3
commit b2354ae341
7 changed files with 18 additions and 19 deletions

View File

@ -37,6 +37,7 @@ class Vector {
// Setters.
// FIXME: Handle downsizing.
// TODO: Rename this so it is clear that this only affects capacity.
void Resize(uint64_t capacity);
void PushBack(const T& item);

View File

@ -72,8 +72,8 @@ glcr::ErrorOr<glcr::Vector<glcr::String>> ListDirectory(glcr::StringView path) {
auto file_views = glcr::StrSplit(dir.filenames(), ',');
glcr::Vector<glcr::String> files;
for (uint64_t i = 0; i < file_views.size(); i++) {
files.PushBack(file_views[i]);
for (const auto& view : glcr::StrSplit(dir.filenames(), ',')) {
files.PushBack(view);
}
return files;
}

View File

@ -39,8 +39,8 @@ glcr::Status DenaliServer::HandleReadMany(const ReadManyRequest& req,
}
uint64_t sector_cnt = 0;
for (uint64_t i = 0; i < req.sector_cnt().size(); i++) {
sector_cnt += req.sector_cnt().at(i);
for (uint64_t cnt : req.sector_cnt()) {
sector_cnt += cnt;
}
uint64_t region_paddr;
mmth::OwnedMemoryRegion region = mmth::OwnedMemoryRegion::ContiguousPhysical(

View File

@ -55,9 +55,8 @@ void Terminal::ExecuteCommand(const glcr::String& command) {
if (!files_or.ok()) {
console_.WriteString(glcr::StrFormat("Error: {}\n", files_or.error()));
} else {
auto& files = files_or.value();
for (uint64_t i = 0; i < files.size(); i++) {
console_.WriteString(files[i]);
for (const auto& file : files_or.value()) {
console_.WriteString(file);
console_.WriteChar('\n');
}
}

View File

@ -94,8 +94,8 @@ glcr::Status VFSServer::HandleGetDirectory(const GetDirectoryRequest& request,
}
glcr::VariableStringBuilder filelist;
for (uint64_t i = 0; i < files.size(); i++) {
filelist.PushBack(glcr::StringView(files.at(i).name, files.at(i).name_len));
for (const DirEntry& file : files) {
filelist.PushBack(glcr::StringView(file.name, file.name_len));
filelist.PushBack(',');
}
// Remove trailing comma.

View File

@ -47,10 +47,9 @@ uint64_t main(uint64_t port_cap) {
glcr::Vector<glcr::StringView> files =
glcr::StrSplit(init_file.as_str(), '\n');
for (uint64_t i = 0; i < files.size(); i++) {
if (!files[i].empty()) {
mmth::File binary =
mmth::File::Open(glcr::StrFormat("/bin/{}", files[i]));
for (glcr::StringView& file : files) {
if (!file.empty()) {
mmth::File binary = mmth::File::Open(glcr::StrFormat("/bin/{}", file));
ASSIGN_OR_RETURN(client_cap, server->CreateClientCap());
auto error_or = mmth::SpawnProcessFromElfRegion(

View File

@ -65,9 +65,9 @@ void Process::Exit(uint64_t exit_code) {
state_ = CLEANUP;
exit_code_ = exit_code;
for (uint64_t i = 0; i < threads_.size(); i++) {
if (!threads_[i]->IsDying()) {
threads_[i]->SetState(Thread::CLEANUP);
for (const auto& t : threads_) {
if (!t->IsDying()) {
t->SetState(Thread::CLEANUP);
}
}
@ -93,9 +93,9 @@ void Process::Cleanup() {
}
// 1. For each thread, call cleanup.
for (uint64_t i = 0; i < threads_.size(); i++) {
if (threads_[i]->GetState() == Thread::CLEANUP) {
threads_[i]->Cleanup();
for (const auto& t : threads_) {
if (t->GetState() == Thread::CLEANUP) {
t->Cleanup();
}
}