diff --git a/lib/glacier/container/vector.h b/lib/glacier/container/vector.h index 64e11b8..eafeb78 100644 --- a/lib/glacier/container/vector.h +++ b/lib/glacier/container/vector.h @@ -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); diff --git a/lib/mammoth/file/file.cpp b/lib/mammoth/file/file.cpp index 7d2a9a7..b1c4e74 100644 --- a/lib/mammoth/file/file.cpp +++ b/lib/mammoth/file/file.cpp @@ -72,8 +72,8 @@ glcr::ErrorOr> ListDirectory(glcr::StringView path) { auto file_views = glcr::StrSplit(dir.filenames(), ','); glcr::Vector 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; } diff --git a/sys/denali/denali_server.cpp b/sys/denali/denali_server.cpp index ef6d9d4..ba99e3e 100644 --- a/sys/denali/denali_server.cpp +++ b/sys/denali/denali_server.cpp @@ -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( diff --git a/sys/teton/terminal.cpp b/sys/teton/terminal.cpp index c4d14c9..9adb28d 100644 --- a/sys/teton/terminal.cpp +++ b/sys/teton/terminal.cpp @@ -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'); } } diff --git a/sys/victoriafalls/victoriafalls_server.cpp b/sys/victoriafalls/victoriafalls_server.cpp index fbc5e42..c48be7b 100644 --- a/sys/victoriafalls/victoriafalls_server.cpp +++ b/sys/victoriafalls/victoriafalls_server.cpp @@ -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. diff --git a/sys/yellowstone/yellowstone.cpp b/sys/yellowstone/yellowstone.cpp index ced7332..5efc089 100644 --- a/sys/yellowstone/yellowstone.cpp +++ b/sys/yellowstone/yellowstone.cpp @@ -47,10 +47,9 @@ uint64_t main(uint64_t port_cap) { glcr::Vector 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( diff --git a/zion/object/process.cpp b/zion/object/process.cpp index 8f45086..6fde4f1 100644 --- a/zion/object/process.cpp +++ b/zion/object/process.cpp @@ -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(); } }