From 46fa5b45fc89eeb0381f50f0e6920c0b08be9813 Mon Sep 17 00:00:00 2001 From: Alexey Tourbin Date: Sat, 28 Nov 2009 12:04:52 +0300 Subject: [PATCH] pkgcache.cc (AllTargets): optimize out CheckDep() calls --- apt/apt-pkg/pkgcache.cc | 34 ++++++++++++---------------------- 1 file changed, 12 insertions(+), 22 deletions(-) diff --git a/apt/apt-pkg/pkgcache.cc b/apt/apt-pkg/pkgcache.cc index 82506d7..24edf5e 100644 --- a/apt/apt-pkg/pkgcache.cc +++ b/apt/apt-pkg/pkgcache.cc @@ -37,6 +37,8 @@ #include #include +#include + #include #include /*}}}*/ @@ -393,11 +395,9 @@ bool pkgCache::DepIterator::SmartTargetPkg(PkgIterator &Result) must be delete [] 'd */ pkgCache::Version **pkgCache::DepIterator::AllTargets() { - Version **Res = 0; + Version *Res[1024]; unsigned int Size = 0; - while (1) { - Version **End = Res; PkgIterator DPkg = TargetPkg(); // Walk along the actual package providing versions @@ -425,9 +425,8 @@ pkgCache::Version **pkgCache::DepIterator::AllTargets() continue; } - Size++; - if (Res != 0) - *End++ = v; + assert(Size < sizeof(Res)/sizeof(*Res)); + Res[Size++] = v; } // Follow all provides @@ -455,25 +454,16 @@ pkgCache::Version **pkgCache::DepIterator::AllTargets() continue; } - Size++; - if (Res != 0) - *End++ = v; + assert(Size < sizeof(Res)/sizeof(*Res)); + Res[Size++] = v; } - - // Do it again and write it into the array - if (Res == 0) - { - Res = new Version *[Size+1]; - Size = 0; - } - else - { - *End = 0; - break; - } } - return Res; + Version **Ret = new Version *[Size+1]; + if (Size) + memcpy(Ret, Res, Size*sizeof(*Res)); + Ret[Size] = 0; + return Ret; } /*}}}*/ // DepIterator::GlobOr - Compute an OR group /*{{{*/