1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 10:58:12 +00:00

Kernel: Implement helper to find multiple Regions in a Range

This commit is contained in:
Hendiadyoin1 2021-02-24 16:44:00 +01:00 committed by Andreas Kling
parent 7874b89426
commit 61f0aa6e75
2 changed files with 26 additions and 0 deletions

View file

@ -1,5 +1,6 @@
/*
* Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2021, Leon Albrecht <leon2002.la@gmail.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -158,6 +159,27 @@ Region* Space::find_region_containing(const Range& range)
return nullptr;
}
Vector<Region*> Space::find_regions_intersecting(const Range& range)
{
Vector<Region*> regions = {};
size_t total_size_collected = 0;
ScopedSpinLock lock(m_lock);
// FIXME: Maybe take the cache from the single lookup?
for (auto& region : m_regions) {
if (region.range().base() < range.end() && region.range().end() > range.base()) {
regions.append(&region);
total_size_collected += region.size() - region.range().intersect(range).size();
if (total_size_collected == range.size())
break;
}
}
return regions;
}
Region& Space::add_region(NonnullOwnPtr<Region> region)
{
auto* ptr = region.ptr();