Skip to content

Commit

Permalink
Bug 1846695 - Have a trivially move assignable and constructible Star…
Browse files Browse the repository at this point in the history
…tupCacheEntry::KeyValuePair. r=xpcom-reviewers,emilio

Depends on D182731

Differential Revision: https://phabricator.services.mozilla.com/D185065
  • Loading branch information
jensstutte committed Dec 12, 2023
1 parent f14147d commit c54ac1d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
11 changes: 6 additions & 5 deletions startupcache/StartupCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand All @@ -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();
Expand Down
12 changes: 11 additions & 1 deletion startupcache/StartupCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit c54ac1d

Please sign in to comment.