Move many loops over glcr::Vector to range-based loops.
This commit is contained in:
parent
c06d1741f3
commit
b2354ae341
|
@ -37,6 +37,7 @@ class Vector {
|
||||||
|
|
||||||
// Setters.
|
// Setters.
|
||||||
// FIXME: Handle downsizing.
|
// FIXME: Handle downsizing.
|
||||||
|
// TODO: Rename this so it is clear that this only affects capacity.
|
||||||
void Resize(uint64_t capacity);
|
void Resize(uint64_t capacity);
|
||||||
|
|
||||||
void PushBack(const T& item);
|
void PushBack(const T& item);
|
||||||
|
|
|
@ -72,8 +72,8 @@ glcr::ErrorOr<glcr::Vector<glcr::String>> ListDirectory(glcr::StringView path) {
|
||||||
|
|
||||||
auto file_views = glcr::StrSplit(dir.filenames(), ',');
|
auto file_views = glcr::StrSplit(dir.filenames(), ',');
|
||||||
glcr::Vector<glcr::String> files;
|
glcr::Vector<glcr::String> files;
|
||||||
for (uint64_t i = 0; i < file_views.size(); i++) {
|
for (const auto& view : glcr::StrSplit(dir.filenames(), ',')) {
|
||||||
files.PushBack(file_views[i]);
|
files.PushBack(view);
|
||||||
}
|
}
|
||||||
return files;
|
return files;
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,8 +39,8 @@ glcr::Status DenaliServer::HandleReadMany(const ReadManyRequest& req,
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t sector_cnt = 0;
|
uint64_t sector_cnt = 0;
|
||||||
for (uint64_t i = 0; i < req.sector_cnt().size(); i++) {
|
for (uint64_t cnt : req.sector_cnt()) {
|
||||||
sector_cnt += req.sector_cnt().at(i);
|
sector_cnt += cnt;
|
||||||
}
|
}
|
||||||
uint64_t region_paddr;
|
uint64_t region_paddr;
|
||||||
mmth::OwnedMemoryRegion region = mmth::OwnedMemoryRegion::ContiguousPhysical(
|
mmth::OwnedMemoryRegion region = mmth::OwnedMemoryRegion::ContiguousPhysical(
|
||||||
|
|
|
@ -55,9 +55,8 @@ void Terminal::ExecuteCommand(const glcr::String& command) {
|
||||||
if (!files_or.ok()) {
|
if (!files_or.ok()) {
|
||||||
console_.WriteString(glcr::StrFormat("Error: {}\n", files_or.error()));
|
console_.WriteString(glcr::StrFormat("Error: {}\n", files_or.error()));
|
||||||
} else {
|
} else {
|
||||||
auto& files = files_or.value();
|
for (const auto& file : files_or.value()) {
|
||||||
for (uint64_t i = 0; i < files.size(); i++) {
|
console_.WriteString(file);
|
||||||
console_.WriteString(files[i]);
|
|
||||||
console_.WriteChar('\n');
|
console_.WriteChar('\n');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -94,8 +94,8 @@ glcr::Status VFSServer::HandleGetDirectory(const GetDirectoryRequest& request,
|
||||||
}
|
}
|
||||||
|
|
||||||
glcr::VariableStringBuilder filelist;
|
glcr::VariableStringBuilder filelist;
|
||||||
for (uint64_t i = 0; i < files.size(); i++) {
|
for (const DirEntry& file : files) {
|
||||||
filelist.PushBack(glcr::StringView(files.at(i).name, files.at(i).name_len));
|
filelist.PushBack(glcr::StringView(file.name, file.name_len));
|
||||||
filelist.PushBack(',');
|
filelist.PushBack(',');
|
||||||
}
|
}
|
||||||
// Remove trailing comma.
|
// Remove trailing comma.
|
||||||
|
|
|
@ -47,10 +47,9 @@ uint64_t main(uint64_t port_cap) {
|
||||||
glcr::Vector<glcr::StringView> files =
|
glcr::Vector<glcr::StringView> files =
|
||||||
glcr::StrSplit(init_file.as_str(), '\n');
|
glcr::StrSplit(init_file.as_str(), '\n');
|
||||||
|
|
||||||
for (uint64_t i = 0; i < files.size(); i++) {
|
for (glcr::StringView& file : files) {
|
||||||
if (!files[i].empty()) {
|
if (!file.empty()) {
|
||||||
mmth::File binary =
|
mmth::File binary = mmth::File::Open(glcr::StrFormat("/bin/{}", file));
|
||||||
mmth::File::Open(glcr::StrFormat("/bin/{}", files[i]));
|
|
||||||
|
|
||||||
ASSIGN_OR_RETURN(client_cap, server->CreateClientCap());
|
ASSIGN_OR_RETURN(client_cap, server->CreateClientCap());
|
||||||
auto error_or = mmth::SpawnProcessFromElfRegion(
|
auto error_or = mmth::SpawnProcessFromElfRegion(
|
||||||
|
|
|
@ -65,9 +65,9 @@ void Process::Exit(uint64_t exit_code) {
|
||||||
state_ = CLEANUP;
|
state_ = CLEANUP;
|
||||||
exit_code_ = exit_code;
|
exit_code_ = exit_code;
|
||||||
|
|
||||||
for (uint64_t i = 0; i < threads_.size(); i++) {
|
for (const auto& t : threads_) {
|
||||||
if (!threads_[i]->IsDying()) {
|
if (!t->IsDying()) {
|
||||||
threads_[i]->SetState(Thread::CLEANUP);
|
t->SetState(Thread::CLEANUP);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,9 +93,9 @@ void Process::Cleanup() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 1. For each thread, call cleanup.
|
// 1. For each thread, call cleanup.
|
||||||
for (uint64_t i = 0; i < threads_.size(); i++) {
|
for (const auto& t : threads_) {
|
||||||
if (threads_[i]->GetState() == Thread::CLEANUP) {
|
if (t->GetState() == Thread::CLEANUP) {
|
||||||
threads_[i]->Cleanup();
|
t->Cleanup();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue