Move glcr::Array & glcr::ArrayView loops to range-based.

This commit is contained in:
Drew Galbraith 2024-01-11 17:39:55 -08:00
parent 0a57d149b6
commit 5eb72da9c8
3 changed files with 9 additions and 10 deletions

View File

@ -194,8 +194,7 @@ template <typename K, typename V, class H>
void HashMap<K, V, H>::Resize(uint64_t new_size) {
Array<LinkedList<Pair<K, V>>> new_data(new_size);
for (uint64_t i = 0; i < data_.size(); i++) {
auto& ll = data_[i];
for (auto& ll : data_) {
while (!ll.empty()) {
auto pair = ll.PopFront();
uint64_t hc = H()(pair.first());

View File

@ -47,16 +47,16 @@ VariableMemoryObject::VariableMemoryObject(uint64_t size) : size_(size) {
// FIXME: Do this lazily.
uint64_t num_pages = size_ / 0x1000;
phys_page_list_ = glcr::Array<uint64_t>(num_pages);
for (uint64_t i = 0; i < phys_page_list_.size(); i++) {
phys_page_list_[i] = 0;
for (uint64_t& page : phys_page_list_) {
page = 0;
}
}
VariableMemoryObject::~VariableMemoryObject() {
for (uint64_t p = 0; p < phys_page_list_.size(); p++) {
if (phys_page_list_[p] != 0) {
for (uint64_t& page : phys_page_list_) {
if (page != 0) {
// TODO: We may be able to do some sort of coalescing here.
phys_mem::FreePage(phys_page_list_[p]);
phys_mem::FreePage(page);
}
}
}

View File

@ -28,12 +28,12 @@ glcr::ErrorOr<IpcMessage> TranslateRequestToIpcMessage(const T& req) {
glcr::ArrayView<const z_cap_t> caps(req.caps, req.num_caps);
message.caps.Resize(caps.size());
for (uint64_t i = 0; i < caps.size(); i++) {
for (uint64_t capid : caps) {
// FIXME: This would feel safer closer to the relevant syscall.
// FIXME: Race conditions on get->check->release here. Would be better to
// have that as a single call on the process. (This pattern repeats other
// places too).
auto cap = gScheduler->CurrentProcess().GetCapability(caps[i]);
auto cap = gScheduler->CurrentProcess().GetCapability(capid);
if (!cap) {
return glcr::CAP_NOT_FOUND;
}
@ -41,7 +41,7 @@ glcr::ErrorOr<IpcMessage> TranslateRequestToIpcMessage(const T& req) {
return glcr::CAP_PERMISSION_DENIED;
}
message.caps.PushBack(
gScheduler->CurrentProcess().ReleaseCapability(caps[i]));
gScheduler->CurrentProcess().ReleaseCapability(capid));
}
return message;