diff options
| author | David Kalnischkies <david@kalnischkies.de> | 2025-01-30 18:03:26 +0000 |
|---|---|---|
| committer | David Kalnischkies <david@kalnischkies.de> | 2025-01-30 19:10:50 +0000 |
| commit | 1bc8dab8df60c5da7cc817bec5f53e60f7eb9817 (patch) | |
| tree | 2d67b584affdebb7726c98072462901763bc90c5 /cmdline | |
| parent | 1bc221a9dd22baa6e2e516d45dc858774cafddd0 (diff) | |
Drop unused version stanza size info from binary cache
Same reason as with the description size before, but this one had
actually one extremely dated user in src:apt left with dumpavail,
which is changed to an implementation that is (in comparison) a bit
slower, but should be good enough for a command that is ideally not
used anymore (even if codesearch suggests otherwise).
After all, what makes this a bit slower is not that we don't know the
size, but that this one does additional work preparing for accessing
the fields which we don't do. In exchange pkgTagFile has a better
implementation for "Jitter" than the old code that we would "just"
need to copy here if speed were really an issue.
Diffstat (limited to 'cmdline')
| -rw-r--r-- | cmdline/apt-cache.cc | 50 |
1 files changed, 19 insertions, 31 deletions
diff --git a/cmdline/apt-cache.cc b/cmdline/apt-cache.cc index 7fdd4dff2..4ad0b0099 100644 --- a/cmdline/apt-cache.cc +++ b/cmdline/apt-cache.cc @@ -464,7 +464,6 @@ static bool DumpAvail(CommandLine &) stdoutfd.OpenDescriptor(STDOUT_FILENO, FileFd::WriteOnly, false); // Iterate over all the package files and write them out. - char *Buffer = new char[Cache->HeaderP->MaxVerFileSize+10]; for (pkgCache::VerFile **J = VFList; *J != 0;) { pkgCache::PkgFileIterator File(*Cache, Cache->PkgFileP + (*J)->File); @@ -472,40 +471,23 @@ static bool DumpAvail(CommandLine &) FileFd PkgF(File.FileName(),FileFd::ReadOnly, FileFd::Extension); if (_error->PendingError() == true) break; - - /* Write all of the records from this package file, since we - already did locality sorting we can now just seek through the - file in read order. We apply 1 more optimization here, since often - there will be < 1 byte gaps between records (for the \n) we read that - into the next buffer and offset a bit.. */ - unsigned long Pos = 0; + + pkgTagFile tagsfile(&PkgF, Cache->HeaderP->MaxVerFileSize); + pkgTagSection Tags; + for (; *J != 0; J++) { if (Cache->PkgFileP + (*J)->File != File) break; - - const pkgCache::VerFile &VF = **J; - // Read the record and then write it out again. - unsigned long Jitter = VF.Offset - Pos; - if (Jitter > 8) - { - if (PkgF.Seek(VF.Offset) == false) - break; - Jitter = 0; - } - - if (PkgF.Read(Buffer,VF.Size + Jitter) == false) + const pkgCache::VerFile &VF = **J; + if (not tagsfile.Jump(Tags, VF.Offset)) break; - Buffer[VF.Size + Jitter] = '\n'; - // See above.. if ((File->Flags & pkgCache::Flag::NotSource) == pkgCache::Flag::NotSource) { - pkgTagSection Tags; - if (Tags.Scan(Buffer+Jitter,VF.Size+1) == false || - Tags.Write(stdoutfd, NULL, RW) == false || - stdoutfd.Write("\n", 1) == false) + if (not Tags.Write(stdoutfd, NULL, RW) || + not stdoutfd.Write("\n", 1)) { _error->Error("Internal Error, Unable to parse a package record"); break; @@ -513,18 +495,24 @@ static bool DumpAvail(CommandLine &) } else { - if (stdoutfd.Write(Buffer + Jitter, VF.Size + 1) == false) + char const *Start, *Stop; + Tags.GetSection(Start, Stop); + for (; Start < Stop; --Stop) + if (std::string_view{"\n\r"}.find(*(Stop - 1)) == std::string_view::npos) + break; + if (not stdoutfd.Write(Start, Stop - Start) || + not stdoutfd.Write("\n\n", 2)) + { + _error->Error("Internal Error, Unable to parse a package record"); break; + } } - - Pos = VF.Offset + VF.Size; } - if (_error->PendingError() == true) + if (_error->PendingError()) break; } - delete [] Buffer; delete [] VFList; return !_error->PendingError(); } |
