зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1550037 - patch 3 - Remove mAddr from the ShmBlock struct, as mShmem->memory() is now a trivial inline accessor. r=jwatt
In mozilla::ipc::SharedMemory, the memory() method was virtual, so we cached the address here (although the compiler would likely have inlined the accessor as the `final` concrete subclass was known). Anyhow, in base::SharedMemory it's a trivial (non-virtual) accessor, so there's no sense in shadowing it here. Differential Revision: https://phabricator.services.mozilla.com/D68789 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
68661385f7
Коммит
a7a8713b2b
|
@ -270,20 +270,19 @@ class FontList {
|
|||
private:
|
||||
struct ShmBlock {
|
||||
// Takes ownership of aShmem
|
||||
ShmBlock(base::SharedMemory* aShmem, void* aAddr)
|
||||
: mShmem(aShmem), mAddr(aAddr) {}
|
||||
ShmBlock(base::SharedMemory* aShmem) : mShmem(aShmem) {}
|
||||
|
||||
// Get pointer to the mapped memory.
|
||||
void* Memory() const { return mShmem->memory(); }
|
||||
|
||||
// The first 32-bit word of each block holds the current amount allocated
|
||||
// in that block; this is updated whenever a new record is stored in the
|
||||
// block.
|
||||
std::atomic<uint32_t>& Allocated() const {
|
||||
return *static_cast<std::atomic<uint32_t>*>(mAddr);
|
||||
return *static_cast<std::atomic<uint32_t>*>(Memory());
|
||||
}
|
||||
|
||||
mozilla::UniquePtr<base::SharedMemory> mShmem;
|
||||
void* mAddr; // Address where the shared memory block is mapped in this
|
||||
// process; avoids virtual call to mShmem->memory() each time
|
||||
// we need to convert between Pointer and a real C++ pointer.
|
||||
};
|
||||
|
||||
Header& GetHeader() {
|
||||
|
|
|
@ -60,7 +60,7 @@ void* Pointer::ToPtr(FontList* aFontList) const {
|
|||
}
|
||||
MOZ_ASSERT(block < aFontList->mBlocks.Length());
|
||||
}
|
||||
return static_cast<char*>(aFontList->mBlocks[block]->mAddr) + Offset();
|
||||
return static_cast<char*>(aFontList->mBlocks[block]->Memory()) + Offset();
|
||||
}
|
||||
|
||||
void String::Assign(const nsACString& aString, FontList* aList) {
|
||||
|
@ -524,17 +524,11 @@ bool FontList::AppendShmBlock() {
|
|||
MOZ_CRASH("failed to create shared memory");
|
||||
return false;
|
||||
}
|
||||
if (!newShm->Map(SHM_BLOCK_SIZE)) {
|
||||
if (!newShm->Map(SHM_BLOCK_SIZE) || !newShm->memory()) {
|
||||
MOZ_CRASH("failed to map shared memory");
|
||||
}
|
||||
|
||||
char* addr = static_cast<char*>(newShm->memory());
|
||||
if (!addr) {
|
||||
MOZ_CRASH("null shared memory?");
|
||||
return false;
|
||||
}
|
||||
|
||||
ShmBlock* block = new ShmBlock(newShm, addr);
|
||||
ShmBlock* block = new ShmBlock(newShm);
|
||||
// Allocate space for the Allocated() header field present in all blocks
|
||||
block->Allocated().store(4);
|
||||
|
||||
|
@ -576,14 +570,10 @@ FontList::ShmBlock* FontList::GetBlockFromParent(uint32_t aIndex) {
|
|||
if (!newShm->SetHandle(handle, true)) {
|
||||
MOZ_CRASH("failed to set shm handle");
|
||||
}
|
||||
if (!newShm->Map(SHM_BLOCK_SIZE)) {
|
||||
if (!newShm->Map(SHM_BLOCK_SIZE) || !newShm->memory()) {
|
||||
MOZ_CRASH("failed to map shared memory");
|
||||
}
|
||||
char* addr = static_cast<char*>(newShm->memory());
|
||||
if (!addr) {
|
||||
MOZ_CRASH("null shared memory?");
|
||||
}
|
||||
return new ShmBlock(newShm, addr);
|
||||
return new ShmBlock(newShm);
|
||||
}
|
||||
|
||||
bool FontList::UpdateShmBlocks() {
|
||||
|
@ -924,7 +914,7 @@ Pointer FontList::ToSharedPointer(const void* aPtr) {
|
|||
const char* p = (const char*)aPtr;
|
||||
const uint32_t blockCount = mBlocks.Length();
|
||||
for (uint32_t i = 0; i < blockCount; ++i) {
|
||||
const char* blockAddr = (const char*)mBlocks[i]->mAddr;
|
||||
const char* blockAddr = (const char*)mBlocks[i]->Memory();
|
||||
if (p >= blockAddr && p < blockAddr + SHM_BLOCK_SIZE) {
|
||||
return Pointer(i, p - blockAddr);
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче