diff options
| author | Julian Andres Klode <julian.klode@canonical.com> | 2025-02-19 12:30:51 +0100 |
|---|---|---|
| committer | Julian Andres Klode <julian.klode@canonical.com> | 2025-03-06 20:06:40 +0100 |
| commit | 56c14eab8f399497295bb74d551dc49a4a763486 (patch) | |
| tree | b32486fd709627f13cf40e5df101c1c67ca2e655 /apt-pkg/solver3.h | |
| parent | b63127f956c7768c75e4b10f8f3ccecd6058066f (diff) | |
solver3: Simplify Var pointer tagging
Use an integer and tag the lowest bit manually. This makes it
much easier to next convert this into a literal.
Add some constexpr and remove an unnecessary assertion on
CastPkg().
Diffstat (limited to 'apt-pkg/solver3.h')
| -rw-r--r-- | apt-pkg/solver3.h | 31 |
1 files changed, 16 insertions, 15 deletions
diff --git a/apt-pkg/solver3.h b/apt-pkg/solver3.h index 0ad0800ba..e9f1ced7b 100644 --- a/apt-pkg/solver3.h +++ b/apt-pkg/solver3.h @@ -304,47 +304,48 @@ class Solver */ struct APT::Solver::Var { - uint32_t IsVersion : 1; - uint32_t MapPtr : 31; + uint32_t value; - Var() : IsVersion(0), MapPtr(0) {} - explicit Var(pkgCache::PkgIterator const &Pkg) : IsVersion(0), MapPtr(Pkg.MapPointer()) {} - explicit Var(pkgCache::VerIterator const &Ver) : IsVersion(1), MapPtr(Ver.MapPointer()) {} + explicit constexpr Var(uint32_t value = 0) : value{value} {} + explicit Var(pkgCache::PkgIterator const &Pkg) : value(uint32_t(Pkg.MapPointer()) << 1) {} + explicit Var(pkgCache::VerIterator const &Ver) : value(uint32_t(Ver.MapPointer()) << 1 | 1) {} + + inline constexpr bool isVersion() const { return value & 1; } + inline constexpr uint32_t mapPtr() const { return value >> 1; } // \brief Return the package, if any, otherwise 0. map_pointer<pkgCache::Package> Pkg() const { - return IsVersion ? 0 : map_pointer<pkgCache::Package>{(uint32_t)MapPtr}; + return isVersion() ? 0 : map_pointer<pkgCache::Package>{mapPtr()}; } // \brief Return the version, if any, otherwise 0. map_pointer<pkgCache::Version> Ver() const { - return IsVersion ? map_pointer<pkgCache::Version>{(uint32_t)MapPtr} : 0; + return isVersion() ? map_pointer<pkgCache::Version>{mapPtr()} : 0; } // \brief Return the package iterator if storing a package, or an empty one pkgCache::PkgIterator Pkg(pkgCache &cache) const { - return IsVersion ? pkgCache::PkgIterator() : pkgCache::PkgIterator(cache, cache.PkgP + Pkg()); + return isVersion() ? pkgCache::PkgIterator() : pkgCache::PkgIterator(cache, cache.PkgP + Pkg()); } // \brief Return the version iterator if storing a package, or an empty end. pkgCache::VerIterator Ver(pkgCache &cache) const { - return IsVersion ? pkgCache::VerIterator(cache, cache.VerP + Ver()) : pkgCache::VerIterator(); + return isVersion() ? pkgCache::VerIterator(cache, cache.VerP + Ver()) : pkgCache::VerIterator(); } // \brief Return a package, cast from version if needed pkgCache::PkgIterator CastPkg(pkgCache &cache) const { - assert(MapPtr != 0); - return IsVersion ? Ver(cache).ParentPkg() : Pkg(cache); + return isVersion() ? Ver(cache).ParentPkg() : Pkg(cache); } // \brief Check if there is no reason. - bool empty() const + constexpr bool empty() const { - return IsVersion == 0 && MapPtr == 0; + return value == 0; } - bool operator==(Var const other) const + constexpr bool operator==(Var const other) const { - return IsVersion == other.IsVersion && MapPtr == other.MapPtr; + return value == other.value; } std::string toString(pkgCache &cache) const |
