From faf04db603e8651a48a4cb04b02e921678f43427 Mon Sep 17 00:00:00 2001 From: Gleb Fotengauer-Malinovskiy Date: Fri, 16 Dec 2016 18:51:54 +0300 Subject: [PATCH] Optimize rpmstrPool usage Introduce global rpmstrPool object and make all rpmds constructors use it. --- apt/apt-pkg/Makefile.am | 2 ++ apt/apt-pkg/rpm/rpmlistparser.cc | 7 ++++--- apt/apt-pkg/rpm/rpmsrcrecords.cc | 7 ++++--- apt/apt-pkg/rpm/rpmstrPool.cc | 21 +++++++++++++++++++++ apt/apt-pkg/rpm/rpmstrPool.h | 8 ++++++++ apt/apt-pkg/rpm/rpmversion.cc | 5 +++-- 6 files changed, 42 insertions(+), 8 deletions(-) create mode 100644 apt/apt-pkg/rpm/rpmstrPool.cc create mode 100644 apt/apt-pkg/rpm/rpmstrPool.h diff --git a/apt/apt-pkg/Makefile.am b/apt/apt-pkg/Makefile.am index f1d8cd2..9fe71ea 100644 --- a/apt/apt-pkg/Makefile.am +++ b/apt/apt-pkg/Makefile.am @@ -53,6 +53,8 @@ libapt_pkg_la_SOURCES = \ rpm/rpmrecords.h \ rpm/rpmsrcrecords.cc \ rpm/rpmsrcrecords.h \ + rpm/rpmstrPool.cc \ + rpm/rpmstrPool.h \ rpm/rpmsystem.cc \ rpm/rpmsystem.h \ rpm/rpmversion.cc \ diff --git a/apt/apt-pkg/rpm/rpmlistparser.cc b/apt/apt-pkg/rpm/rpmlistparser.cc index 9739104..04adf1c 100644 --- a/apt/apt-pkg/rpm/rpmlistparser.cc +++ b/apt/apt-pkg/rpm/rpmlistparser.cc @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -460,9 +461,9 @@ bool rpmListParser::ParseDepends(pkgCache::VerIterator Ver, { #if RPM_VERSION >= 0x040404 rpmds rpmlibProv = NULL; - rpmds ds = rpmdsSingle(RPMTAG_PROVIDENAME, - namel[i], verl?verl[i]:NULL, flagl[i]); - rpmdsRpmlib(&rpmlibProv, NULL); + rpmds ds = dsSingleGlobal(RPMTAG_PROVIDENAME, + namel[i], verl?verl[i]:NULL, flagl[i]); + dsRpmlibGlobal(&rpmlibProv, NULL); int res = rpmdsSearch(rpmlibProv, ds) >= 0; rpmdsFree(ds); rpmdsFree(rpmlibProv); diff --git a/apt/apt-pkg/rpm/rpmsrcrecords.cc b/apt/apt-pkg/rpm/rpmsrcrecords.cc index d9e9d17..84bed63 100644 --- a/apt/apt-pkg/rpm/rpmsrcrecords.cc +++ b/apt/apt-pkg/rpm/rpmsrcrecords.cc @@ -23,6 +23,7 @@ #include #include #include +#include #include #include @@ -514,9 +515,9 @@ bool rpmSrcRecordParser::BuildDepends(vector { #if RPM_VERSION >= 0x040404 rpmds rpmlibProv = NULL; - rpmds ds = rpmdsSingle(RPMTAG_PROVIDENAME, - namel[i], verl?verl[i]:NULL, flagl[i]); - rpmdsRpmlib(&rpmlibProv, NULL); + rpmds ds = dsSingleGlobal(RPMTAG_PROVIDENAME, + namel[i], verl?verl[i]:NULL, flagl[i]); + dsRpmlibGlobal(&rpmlibProv, NULL); int res = (rpmdsSearch(rpmlibProv, ds) != -1); rpmdsFree(ds); rpmdsFree(rpmlibProv); diff --git a/apt/apt-pkg/rpm/rpmstrPool.cc b/apt/apt-pkg/rpm/rpmstrPool.cc new file mode 100644 index 0000000..77479f6 --- /dev/null +++ b/apt/apt-pkg/rpm/rpmstrPool.cc @@ -0,0 +1,21 @@ +#include +#include + +static rpmstrPool global_rpmstrPool; + +rpmds dsSingleGlobal(rpmTagVal tagN, const char * N, const char * EVR, + rpmsenseFlags Flags) +{ + if (!global_rpmstrPool) + global_rpmstrPool = rpmstrPoolCreate(); + + return rpmdsSinglePool(global_rpmstrPool, tagN, N, EVR, Flags); +} + +int dsRpmlibGlobal(rpmds * dsp, const void * tblp) +{ + if (!global_rpmstrPool) + global_rpmstrPool = rpmstrPoolCreate(); + + return rpmdsRpmlibPool(global_rpmstrPool, dsp, tblp); +} diff --git a/apt/apt-pkg/rpm/rpmstrPool.h b/apt/apt-pkg/rpm/rpmstrPool.h new file mode 100644 index 0000000..3be18f5 --- /dev/null +++ b/apt/apt-pkg/rpm/rpmstrPool.h @@ -0,0 +1,8 @@ +#include +#include +#include + +rpmds dsSingleGlobal(rpmTagVal tagN, const char * N, const char * EVR, + rpmsenseFlags Flags); + +int dsRpmlibGlobal(rpmds * dsp, const void * tblp); diff --git a/apt/apt-pkg/rpm/rpmversion.cc b/apt/apt-pkg/rpm/rpmversion.cc index d54da23..8a09e66 100644 --- a/apt/apt-pkg/rpm/rpmversion.cc +++ b/apt/apt-pkg/rpm/rpmversion.cc @@ -20,6 +20,7 @@ #ifdef HAVE_RPM #include +#include #include #include @@ -207,8 +208,8 @@ bool rpmVersioningSystem::CheckDep(const char *PkgVer, return invert ? false : true; #if RPM_VERSION >= 0x040100 - rpmds pds = rpmdsSingle(RPMTAG_PROVIDENAME, "", PkgVer, PkgFlags); - rpmds dds = rpmdsSingle(RPMTAG_REQUIRENAME, "", DepVer, DepFlags); + rpmds pds = dsSingleGlobal(RPMTAG_PROVIDENAME, "", PkgVer, PkgFlags); + rpmds dds = dsSingleGlobal(RPMTAG_REQUIRENAME, "", DepVer, DepFlags); #if RPM_VERSION >= 0x040201 rpmdsSetNoPromote(pds, _rpmds_nopromote); rpmdsSetNoPromote(dds, _rpmds_nopromote);