summaryrefslogtreecommitdiff
path: root/compiler/utils/swap_space.h
diff options
context:
space:
mode:
author Treehugger Robot <treehugger-gerrit@google.com> 2017-02-22 19:52:51 +0000
committer Gerrit Code Review <noreply-gerritcodereview@google.com> 2017-02-22 19:52:53 +0000
commitf773e851c620d253d02e81a3e2ae115c5862d73c (patch)
tree818183b56279b88228551945c4b919456bb49050 /compiler/utils/swap_space.h
parentce11f8021d6f0d1f88b6487dfd96fb76142676c4 (diff)
parent3e1070239a920cc94b020a621acf4daeccebb140 (diff)
Merge "Avoid excessive allocation of std::set<> nodes in SwapSpace."
Diffstat (limited to 'compiler/utils/swap_space.h')
-rw-r--r--compiler/utils/swap_space.h22
1 files changed, 16 insertions, 6 deletions
diff --git a/compiler/utils/swap_space.h b/compiler/utils/swap_space.h
index 9600907278..c286b820fe 100644
--- a/compiler/utils/swap_space.h
+++ b/compiler/utils/swap_space.h
@@ -45,8 +45,10 @@ class SwapSpace {
private:
// Chunk of space.
struct SpaceChunk {
- uint8_t* ptr;
- size_t size;
+ // We need mutable members as we keep these objects in a std::set<> (providing only const
+ // access) but we modify these members while carefully preserving the std::set<> ordering.
+ mutable uint8_t* ptr;
+ mutable size_t size;
uintptr_t Start() const {
return reinterpret_cast<uintptr_t>(ptr);
@@ -66,13 +68,21 @@ class SwapSpace {
typedef std::set<SpaceChunk, SortChunkByPtr> FreeByStartSet;
// Map size to an iterator to free_by_start_'s entry.
- typedef std::pair<size_t, FreeByStartSet::const_iterator> FreeBySizeEntry;
+ struct FreeBySizeEntry {
+ FreeBySizeEntry(size_t sz, FreeByStartSet::const_iterator entry)
+ : size(sz), free_by_start_entry(entry) { }
+
+ // We need mutable members as we keep these objects in a std::set<> (providing only const
+ // access) but we modify these members while carefully preserving the std::set<> ordering.
+ mutable size_t size;
+ mutable FreeByStartSet::const_iterator free_by_start_entry;
+ };
struct FreeBySizeComparator {
bool operator()(const FreeBySizeEntry& lhs, const FreeBySizeEntry& rhs) {
- if (lhs.first != rhs.first) {
- return lhs.first < rhs.first;
+ if (lhs.size != rhs.size) {
+ return lhs.size < rhs.size;
} else {
- return lhs.second->Start() < rhs.second->Start();
+ return lhs.free_by_start_entry->Start() < rhs.free_by_start_entry->Start();
}
}
};