From c2c98b6e251d221faea879058aa0e92436048e76 Mon Sep 17 00:00:00 2001 From: наб Date: Thu, 14 Nov 2024 17:16:50 +0100 Subject: pkgTagSection::Tag constructors: std::string const& -> std::string_view (always copied) [#if APT_PKG_ABI > 600] --- apt-pkg/tagfile.cc | 28 ++++++++++++++++++++-------- apt-pkg/tagfile.h | 18 ++++++++++++------ 2 files changed, 32 insertions(+), 14 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/tagfile.cc b/apt-pkg/tagfile.cc index aff786df1..4914ba1b3 100644 --- a/apt-pkg/tagfile.cc +++ b/apt-pkg/tagfile.cc @@ -3,10 +3,10 @@ /* ###################################################################### Fast scanner for RFC-822 type header information - + This uses a rotating buffer to load the package information into. The scanner runs over it and isolates and indexes a single section. - + ##################################################################### */ /*}}}*/ // Include Files /*{{{*/ @@ -199,7 +199,7 @@ bool pkgTagFile::Resize(unsigned long long const newSize) /*}}}*/ // TagFile::Step - Advance to the next section /*{{{*/ // --------------------------------------------------------------------- -/* If the Section Scanner fails we refill the buffer and try again. +/* If the Section Scanner fails we refill the buffer and try again. * If that fails too, double the buffer size and try again until a * maximum buffer is reached. */ @@ -466,14 +466,14 @@ bool pkgTagFile::Jump(pkgTagSection &Tag,unsigned long long Offset) if (Tag.Scan(d->Start, d->End - d->Start) == true) return true; - + // This appends a double new line (for the real eof handling) if (Fill() == false) return false; - + if (Tag.Scan(d->Start, d->End - d->Start, false) == false) return _error->Error(_("Unable to parse package file %s (%d)"),d->Fd->Name().c_str(), 2); - + return true; } /*}}}*/ @@ -602,7 +602,7 @@ bool pkgTagSection::Scan(const char *Start,unsigned long MaxLength, bool const R TrimRecord(false,End); return true; } - + Stop++; } @@ -814,7 +814,7 @@ unsigned long long pkgTagSection::FindULLInternal(unsigned int Pos, unsigned lon return Default; strncpy(S,Start,Stop-Start); S[Stop - Start] = 0; - + char *End; unsigned long long Result = strtoull(S,&End,10); if (S == End) @@ -959,15 +959,27 @@ APT_PURE unsigned int pkgTagSection::Count() const { /*{{{*/ } /*}}}*/ // TagSection::Write - Ordered (re)writing of fields /*{{{*/ +#if APT_PKG_ABI > 600 +pkgTagSection::Tag pkgTagSection::Tag::Remove(std::string_view Name) +#else pkgTagSection::Tag pkgTagSection::Tag::Remove(std::string const &Name) +#endif { return Tag(REMOVE, Name, ""); } +#if APT_PKG_ABI > 600 +pkgTagSection::Tag pkgTagSection::Tag::Rename(std::string_view OldName, std::string_view NewName) +#else pkgTagSection::Tag pkgTagSection::Tag::Rename(std::string const &OldName, std::string const &NewName) +#endif { return Tag(RENAME, OldName, NewName); } +#if APT_PKG_ABI > 600 +pkgTagSection::Tag pkgTagSection::Tag::Rewrite(std::string_view Name, std::string_view Data) +#else pkgTagSection::Tag pkgTagSection::Tag::Rewrite(std::string const &Name, std::string const &Data) +#endif { if (Data.empty() == true) return Tag(REMOVE, Name, ""); diff --git a/apt-pkg/tagfile.h b/apt-pkg/tagfile.h index cd1806eb4..b32317cec 100644 --- a/apt-pkg/tagfile.h +++ b/apt-pkg/tagfile.h @@ -3,17 +3,17 @@ /* ###################################################################### Fast scanner for RFC-822 type header information - + This parser handles Debian package files (and others). Their form is RFC-822 type header fields in groups separated by a blank line. - + The parser reads the file and provides methods to step linearly over it or to jump to a pre-recorded start point and read that record. - + A second class is used to perform pre-parsing of the record. It works - by indexing the start of each header field and providing lookup + by indexing the start of each header field and providing lookup functions for header fields. - + ##################################################################### */ /*}}}*/ #ifndef PKGLIB_TAGFILE_H @@ -150,11 +150,17 @@ class APT_PUBLIC pkgTagSection std::string Name; std::string Data; +#if APT_PKG_ABI > 600 + static Tag Remove(std::string_view Name); + static Tag Rename(std::string_view OldName, std::string_view NewName); + static Tag Rewrite(std::string_view Name, std::string_view Data); +#else static Tag Remove(std::string const &Name); static Tag Rename(std::string const &OldName, std::string const &NewName); static Tag Rewrite(std::string const &Name, std::string const &Data); +#endif private: - Tag(ActionType const Action, std::string const &Name, std::string const &Data) : + Tag(ActionType const Action, std::string_view Name, std::string_view Data) : Action(Action), Name(Name), Data(Data) {} }; -- cgit v1.2.3-70-g09d2