forked from ShuriZma/suyu
1
0
Fork 0

Merge pull request #4388 from lioncash/written

buffer_cache: Eliminate redundant map lookup in MarkRegionAsWritten()
This commit is contained in:
bunnei 2020-07-24 11:29:37 -07:00 committed by GitHub
commit d488cb843e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 6 deletions

View File

@ -524,11 +524,8 @@ private:
void MarkRegionAsWritten(VAddr start, VAddr end) { void MarkRegionAsWritten(VAddr start, VAddr end) {
const u64 page_end = end >> WRITE_PAGE_BIT; const u64 page_end = end >> WRITE_PAGE_BIT;
for (u64 page_start = start >> WRITE_PAGE_BIT; page_start <= page_end; ++page_start) { for (u64 page_start = start >> WRITE_PAGE_BIT; page_start <= page_end; ++page_start) {
auto it = written_pages.find(page_start); if (const auto [it, inserted] = written_pages.emplace(page_start, 1); !inserted) {
if (it != written_pages.end()) { ++it->second;
it->second = it->second + 1;
} else {
written_pages.insert_or_assign(page_start, 1);
} }
} }
} }
@ -539,7 +536,7 @@ private:
auto it = written_pages.find(page_start); auto it = written_pages.find(page_start);
if (it != written_pages.end()) { if (it != written_pages.end()) {
if (it->second > 1) { if (it->second > 1) {
it->second = it->second - 1; --it->second;
} else { } else {
written_pages.erase(it); written_pages.erase(it);
} }