mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-03-02 22:37:50 +00:00
Bug 1846695 - Have a trivially move assignable and constructible StartupCacheEntry::KeyValuePair. r=xpcom-reviewers,emilio
Depends on D182731 Differential Revision: https://phabricator.services.mozilla.com/D185065
This commit is contained in:
parent
f14147ddbe
commit
c54ac1d672
@ -520,11 +520,12 @@ Result<Ok, nsresult> StartupCache::WriteToDisk() {
|
||||
MOZ_TRY(mFile->OpenNSPRFileDesc(PR_WRONLY | PR_CREATE_FILE | PR_TRUNCATE,
|
||||
0644, &fd.rwget()));
|
||||
|
||||
nsTArray<std::pair<const nsCString*, StartupCacheEntry*>> entries;
|
||||
nsTArray<StartupCacheEntry::KeyValuePair> entries(mTable.count());
|
||||
for (auto iter = mTable.iter(); !iter.done(); iter.next()) {
|
||||
if (iter.get().value().mRequested) {
|
||||
entries.AppendElement(
|
||||
std::make_pair(&iter.get().key(), &iter.get().value()));
|
||||
StartupCacheEntry::KeyValuePair kv(&iter.get().key(),
|
||||
&iter.get().value());
|
||||
entries.AppendElement(kv);
|
||||
}
|
||||
}
|
||||
|
||||
@ -535,8 +536,8 @@ Result<Ok, nsresult> StartupCache::WriteToDisk() {
|
||||
entries.Sort(StartupCacheEntry::Comparator());
|
||||
loader::OutputBuffer buf;
|
||||
for (auto& e : entries) {
|
||||
auto key = e.first;
|
||||
auto value = e.second;
|
||||
auto* key = e.first;
|
||||
auto* value = e.second;
|
||||
auto uncompressedSize = value->mUncompressedSize;
|
||||
// Set the mHeaderOffsetInFile so we can go back and edit the offset.
|
||||
value->mHeaderOffsetInFile = buf.cursor();
|
||||
|
@ -113,8 +113,18 @@ struct StartupCacheEntry {
|
||||
mRequestedOrder(0),
|
||||
mRequested(true) {}
|
||||
|
||||
// std::pair is not trivially move assignable/constructible, so make our own.
|
||||
struct KeyValuePair {
|
||||
const nsCString* first;
|
||||
StartupCacheEntry* second;
|
||||
KeyValuePair(const nsCString* aKeyPtr, StartupCacheEntry* aValuePtr)
|
||||
: first(aKeyPtr), second(aValuePtr) {}
|
||||
};
|
||||
static_assert(std::is_trivially_move_assignable<KeyValuePair>::value);
|
||||
static_assert(std::is_trivially_move_constructible<KeyValuePair>::value);
|
||||
|
||||
struct Comparator {
|
||||
using Value = std::pair<const nsCString*, StartupCacheEntry*>;
|
||||
using Value = KeyValuePair;
|
||||
|
||||
bool Equals(const Value& a, const Value& b) const {
|
||||
return a.second->mRequestedOrder == b.second->mRequestedOrder;
|
||||
|
Loading…
x
Reference in New Issue
Block a user