mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-28 23:31:56 +00:00
Bug 1594598 - Tweak the control flow in MaybePageAlloc()'s loop. r=glandium
This reduces the indentation level by one for most of the loop body. Differential Revision: https://phabricator.services.mozilla.com/D43837 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
956102ca29
commit
fb493c1481
@ -870,30 +870,32 @@ static void* MaybePageAlloc(const Maybe<arena_id_t>& aArenaId, size_t aReqSize,
|
||||
void* ptr = nullptr;
|
||||
for (uintptr_t n = 0, i = size_t(gMut->Random64(lock)) % kMaxPageAllocs;
|
||||
n < kMaxPageAllocs; n++, i = (i + 1) % kMaxPageAllocs) {
|
||||
if (gMut->IsPageAllocatable(lock, i, now)) {
|
||||
void* pagePtr = gConst->PagePtr(i);
|
||||
bool ok =
|
||||
#ifdef XP_WIN
|
||||
!!VirtualAlloc(pagePtr, kPageSize, MEM_COMMIT, PAGE_READWRITE);
|
||||
#else
|
||||
mprotect(pagePtr, kPageSize, PROT_READ | PROT_WRITE) == 0;
|
||||
#endif
|
||||
size_t usableSize = sMallocTable.malloc_good_size(aReqSize);
|
||||
if (ok) {
|
||||
gMut->SetPageInUse(lock, i, aArenaId, usableSize, allocStack);
|
||||
ptr = pagePtr;
|
||||
if (aZero) {
|
||||
memset(ptr, 0, usableSize);
|
||||
} else {
|
||||
#ifdef DEBUG
|
||||
memset(ptr, kAllocJunk, usableSize);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
LOG("PageAlloc(%zu) -> %p[%zu] (%zu) (z%zu), sAllocDelay <- %zu\n",
|
||||
aReqSize, ptr, i, usableSize, size_t(aZero), size_t(newAllocDelay));
|
||||
break;
|
||||
if (!gMut->IsPageAllocatable(lock, i, now)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
void* pagePtr = gConst->PagePtr(i);
|
||||
bool ok =
|
||||
#ifdef XP_WIN
|
||||
!!VirtualAlloc(pagePtr, kPageSize, MEM_COMMIT, PAGE_READWRITE);
|
||||
#else
|
||||
mprotect(pagePtr, kPageSize, PROT_READ | PROT_WRITE) == 0;
|
||||
#endif
|
||||
size_t usableSize = sMallocTable.malloc_good_size(aReqSize);
|
||||
if (ok) {
|
||||
gMut->SetPageInUse(lock, i, aArenaId, usableSize, allocStack);
|
||||
ptr = pagePtr;
|
||||
if (aZero) {
|
||||
memset(ptr, 0, usableSize);
|
||||
} else {
|
||||
#ifdef DEBUG
|
||||
memset(ptr, kAllocJunk, usableSize);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
LOG("PageAlloc(%zu) -> %p[%zu] (%zu) (z%zu), sAllocDelay <- %zu\n",
|
||||
aReqSize, ptr, i, usableSize, size_t(aZero), size_t(newAllocDelay));
|
||||
break;
|
||||
}
|
||||
|
||||
if (!ptr) {
|
||||
|
Loading…
Reference in New Issue
Block a user