tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit e84a4526c7782b4498190d8954e0ac87e596e100
parent 39db3f6e0d5482c22ab2ebe9e51259420c7c227e
Author: Paul Bone <paul@bone.id.au>
Date:   Wed, 29 Oct 2025 06:32:46 +0000

Bug 1976162 - pt 6. Improve style in basealloc r=glandium

Declare variables with their initialisation.

Differential Revision: https://phabricator.services.mozilla.com/D256417

Diffstat:
Mmemory/build/BaseAlloc.cpp | 14++++----------
1 file changed, 4 insertions(+), 10 deletions(-)

diff --git a/memory/build/BaseAlloc.cpp b/memory/build/BaseAlloc.cpp @@ -16,11 +16,8 @@ MOZ_CONSTINIT BaseAlloc sBaseAlloc; void BaseAlloc::Init() MOZ_REQUIRES(gInitLock) { mMutex.Init(); } bool BaseAlloc::pages_alloc(size_t minsize) MOZ_REQUIRES(mMutex) { - size_t csize; - size_t pminsize; - MOZ_ASSERT(minsize != 0); - csize = CHUNK_CEILING(minsize); + size_t csize = CHUNK_CEILING(minsize); void* base_pages = chunk_alloc(csize, kChunkSize, true); if (!base_pages) { return false; @@ -29,7 +26,7 @@ bool BaseAlloc::pages_alloc(size_t minsize) MOZ_REQUIRES(mMutex) { mPastAddr = (void*)((uintptr_t)base_pages + csize); // Leave enough pages for minsize committed, since otherwise they would // have to be immediately recommitted. - pminsize = PAGE_CEILING(minsize); + size_t pminsize = PAGE_CEILING(minsize); mNextDecommitted = (void*)((uintptr_t)base_pages + pminsize); if (pminsize < csize) { pages_decommit(mNextDecommitted, csize - pminsize); @@ -41,11 +38,8 @@ bool BaseAlloc::pages_alloc(size_t minsize) MOZ_REQUIRES(mMutex) { } void* BaseAlloc::alloc(size_t aSize) { - void* ret; - size_t csize; - // Round size up to nearest multiple of the cacheline size. - csize = CACHELINE_CEILING(aSize); + size_t csize = CACHELINE_CEILING(aSize); MutexAutoLock lock(mMutex); // Make sure there's enough space for the allocation. @@ -55,7 +49,7 @@ void* BaseAlloc::alloc(size_t aSize) { } } // Allocate. - ret = mNextAddr; + void* ret = mNextAddr; mNextAddr = (void*)((uintptr_t)mNextAddr + csize); // Make sure enough pages are committed for the new allocation. if ((uintptr_t)mNextAddr > (uintptr_t)mNextDecommitted) {