Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f530dbf6 authored by Elliott Hughes's avatar Elliott Hughes Committed by Gerrit Code Review
Browse files

Merge "Add a std::string overload to Next."

parents 54368432 e06a8080
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@
#include <sys/cdefs.h>
#include <sys/types.h>

#include <string>
#include <string_view>

#include "android-base/off64_t.h"
@@ -35,6 +36,7 @@ enum {
  kCompressDeflated = 8,  // standard deflate
};

// TODO: remove this when everyone's moved over to std::string.
struct ZipString {
  const uint8_t* name;
  uint16_t name_length;
@@ -187,6 +189,8 @@ int32_t StartIteration(ZipArchiveHandle archive, void** cookie_ptr,
 * Returns 0 on success, -1 if there are no more elements in this
 * archive and lower negative values on failure.
 */
int32_t Next(void* cookie, ZipEntry* data, std::string* name);
// TODO: remove this when everyone's moved over to std::string.
int32_t Next(void* cookie, ZipEntry* data, ZipString* name);

/*
+2 −3
Original line number Diff line number Diff line
@@ -255,9 +255,8 @@ static void ProcessAll(ZipArchiveHandle zah) {
  }

  ZipEntry entry;
  ZipString string;
  while ((err = Next(cookie, &entry, &string)) >= 0) {
    std::string name(string.name, string.name + string.name_length);
  std::string name;
  while ((err = Next(cookie, &entry, &name)) >= 0) {
    if (ShouldInclude(name)) ProcessOne(zah, entry, name);
  }

+9 −0
Original line number Diff line number Diff line
@@ -747,6 +747,15 @@ int32_t FindEntry(const ZipArchiveHandle archive, const std::string_view entryNa
  return FindEntry(archive, static_cast<uint32_t>(ent), data);
}

int32_t Next(void* cookie, ZipEntry* data, std::string* name) {
  ZipString zs;
  int32_t result = Next(cookie, data, &zs);
  if (result == 0) {
    *name = std::string(reinterpret_cast<const char*>(zs.name), zs.name_length);
  }
  return result;
}

int32_t Next(void* cookie, ZipEntry* data, ZipString* name) {
  IterationHandle* handle = reinterpret_cast<IterationHandle*>(cookie);
  if (handle == NULL) {
+1 −1
Original line number Diff line number Diff line
@@ -71,7 +71,7 @@ static void Iterate_all_files(benchmark::State& state) {
  ZipArchiveHandle handle;
  void* iteration_cookie;
  ZipEntry data;
  ZipString name;
  std::string name;

  while (state.KeepRunning()) {
    OpenArchive(temp_file->path, &handle);
+4 −4
Original line number Diff line number Diff line
@@ -118,10 +118,10 @@ static void AssertIterationOrder(const std::string_view prefix, const std::strin
  ZipEntry data;
  std::vector<std::string> names;

  ZipString name;
  std::string name;
  for (size_t i = 0; i < expected_names_sorted.size(); ++i) {
    ASSERT_EQ(0, Next(iteration_cookie, &data, &name));
    names.push_back(std::string(reinterpret_cast<const char*>(name.name), name.name_length));
    names.push_back(name);
  }

  // End of iteration.
@@ -167,7 +167,7 @@ TEST(ziparchive, IterationWithBadPrefixAndSuffix) {
  ASSERT_EQ(0, StartIteration(handle, &iteration_cookie, "x", "y"));

  ZipEntry data;
  ZipString name;
  std::string name;

  // End of iteration.
  ASSERT_EQ(-1, Next(iteration_cookie, &data, &name));
@@ -224,7 +224,7 @@ TEST(ziparchive, TestInvalidDeclaredLength) {
  void* iteration_cookie;
  ASSERT_EQ(0, StartIteration(handle, &iteration_cookie));

  ZipString name;
  std::string name;
  ZipEntry data;

  ASSERT_EQ(Next(iteration_cookie, &data, &name), 0);