/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* vim: set ts=8 sts=2 et sw=2 tw=80: */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
staticinline size_t GetAlignmentOffset(size_t aOffset, size_t aAlign) { auto mod = aOffset % aAlign; return mod ? aAlign - mod : 0;
}
SharedPrefMap::SharedPrefMap(const SharedMemoryHandle& aMapHandle,
size_t aMapSize) { auto map = MakeRefPtr<SharedMemory>();
{ auto result = map->SetHandle(SharedMemory::CloneHandle(aMapHandle),
SharedMemory::OpenRights::RightsReadOnly);
MOZ_RELEASE_ASSERT(result);
}
{ auto result = map->Map(aMapSize);
MOZ_RELEASE_ASSERT(result);
}
// We return literal nsCStrings pointing to the mapped data for preference // names and string values, which means that we may still have references to // the mapped data even after this instance is destroyed. That means that we // need to keep the mapping alive until process shutdown, in order to be safe.
mMappedMemory = map->TakeMapping();
mHandle = map->TakeHandle();
}
SharedPrefMap::SharedPrefMap(SharedPrefMapBuilder&& aBuilder) {
RefPtr<SharedMemory> map; auto result = aBuilder.Finalize(map);
MOZ_RELEASE_ASSERT(result.isOk() && map);
Result<Ok, nsresult> SharedPrefMapBuilder::Finalize(
RefPtr<SharedMemory>& aMap) { using Header = SharedPrefMap::Header;
// Create an array of entry pointers for the entry array, and sort it by // preference name prior to serialization, so that entries can be looked up // using binary search.
nsTArray<Entry*> entries(mEntries.Length()); for (auto& entry : mEntries) {
entries.AppendElement(&entry);
}
entries.Sort([](const Entry* aA, const Entry* aB) { return strcmp(aA->mKeyString, aB->mKeyString);
});
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.