summaryrefslogtreecommitdiff
path: root/apt-pkg/contrib
diff options
context:
space:
mode:
authorJulian Andres Klode <julian.klode@canonical.com>2020-01-17 17:19:56 +0100
committerJulian Andres Klode <julian.klode@canonical.com>2020-01-17 17:19:56 +0100
commit8dc1d3c4662e9009ed56483fd4254ee1154b6e23 (patch)
tree69d06108ae16899e7a655f1149fe757fc138dd18 /apt-pkg/contrib
parent25353dc6646e5b9fff55059a5c85183589cf472d (diff)
mmap: Do not look for empty pool unless we need to
Given that we have a maximum of 12 pools, and much more items to insert, it does not make sense to have two branches in the hot path. Move the search for an empty pool into the unlikely case that no matching pool has been created yet - a condition that is guaranteed to only happens up to 12 times.
Diffstat (limited to 'apt-pkg/contrib')
-rw-r--r--apt-pkg/contrib/mmap.cc17
1 files changed, 9 insertions, 8 deletions
diff --git a/apt-pkg/contrib/mmap.cc b/apt-pkg/contrib/mmap.cc
index ee6a21c83..020491172 100644
--- a/apt-pkg/contrib/mmap.cc
+++ b/apt-pkg/contrib/mmap.cc
@@ -357,25 +357,26 @@ unsigned long DynamicMMap::Allocate(unsigned long ItemSize)
// Look for a matching pool entry
Pool *I;
- Pool *Empty = 0;
for (I = Pools; I != Pools + PoolCount; ++I)
{
- if (I->ItemSize == 0)
- Empty = I;
if (I->ItemSize == ItemSize)
break;
}
- // No pool is allocated, use an unallocated one
- if (I == Pools + PoolCount)
+ // No pool is allocated, use an unallocated one.
+ if (unlikely(I == Pools + PoolCount))
{
+ for (I = Pools; I != Pools + PoolCount; ++I)
+ {
+ if (I->ItemSize == 0)
+ break;
+ }
// Woops, we ran out, the calling code should allocate more.
- if (Empty == 0)
+ if (I == Pools + PoolCount)
{
_error->Error("Ran out of allocation pools");
return 0;
}
-
- I = Empty;
+
I->ItemSize = ItemSize;
I->Count = 0;
}