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

Commit 6e427525 authored by ESWAR MAGATAPALLI (xWF)'s avatar ESWAR MAGATAPALLI (xWF)
Browse files

Revert "[res] Optimize few functions for dtoh() as a noop"

Revert submission 31021037

Reason for revert: Droidmonitor created revert due to b/388342212. Will be verifying through ABTD before submission.

Reverted changes: /q/submissionid:31021037

Change-Id: Ibd9504f9ea147e3849a5df4b924c44f9880c69c2
parent eb759ec5
Loading
Loading
Loading
Loading
+45 −33
Original line number Diff line number Diff line
@@ -152,7 +152,8 @@ static void fill9patchOffsets(Res_png_9patch* patch) {
    patch->colorsOffset = patch->yDivsOffset + (patch->numYDivs * sizeof(int32_t));
}

void Res_value::copyFrom_dtoh_slow(const Res_value& src) {
void Res_value::copyFrom_dtoh(const Res_value& src)
{
    size = dtohs(src.size);
    res0 = src.res0;
    dataType = src.dataType;
@@ -2030,6 +2031,16 @@ status_t ResXMLTree::validateNode(const ResXMLTree_node* node) const
// --------------------------------------------------------------------
// --------------------------------------------------------------------

void ResTable_config::copyFromDeviceNoSwap(const ResTable_config& o) {
    const size_t size = dtohl(o.size);
    if (size >= sizeof(ResTable_config)) {
        *this = o;
    } else {
        memcpy(this, &o, size);
        memset(((uint8_t*)this)+size, 0, sizeof(ResTable_config)-size);
    }
}

/* static */ size_t unpackLanguageOrRegion(const char in[2], const char base,
        char out[4]) {
  if (in[0] & 0x80) {
@@ -2094,7 +2105,8 @@ size_t ResTable_config::unpackRegion(char region[4]) const {
    return unpackLanguageOrRegion(this->country, '0', region);
}

void ResTable_config::copyFromDtoH_slow(const ResTable_config& o) {

void ResTable_config::copyFromDtoH(const ResTable_config& o) {
    copyFromDeviceNoSwap(o);
    size = sizeof(ResTable_config);
    mcc = dtohs(mcc);
@@ -2109,7 +2121,7 @@ void ResTable_config::copyFromDtoH_slow(const ResTable_config& o) {
    screenHeightDp = dtohs(screenHeightDp);
}

void ResTable_config::swapHtoD_slow() {
void ResTable_config::swapHtoD() {
    size = htodl(size);
    mcc = htods(mcc);
    mnc = htods(mnc);
@@ -2133,7 +2145,7 @@ void ResTable_config::swapHtoD_slow() {
    // systems should happen very infrequently (if at all.)
    // The comparison code relies on memcmp low-level optimizations that make it
    // more efficient than strncmp.
    static constexpr char emptyScript[sizeof(l.localeScript)] = {'\0', '\0', '\0', '\0'};
    const char emptyScript[sizeof(l.localeScript)] = {'\0', '\0', '\0', '\0'};
    const char *lScript = l.localeScriptWasComputed ? emptyScript : l.localeScript;
    const char *rScript = r.localeScriptWasComputed ? emptyScript : r.localeScript;

+9 −16
Original line number Diff line number Diff line
@@ -32,10 +32,6 @@ namespace android {
namespace util {

void ReadUtf16StringFromDevice(const uint16_t* src, size_t len, std::string* out) {
  static constexpr bool kDeviceEndiannessSame = dtohs(0x1001) == 0x1001;
  if constexpr (kDeviceEndiannessSame) {
    *out = Utf16ToUtf8({(const char16_t*)src, strnlen16((const char16_t*)src, len)});
  } else {
  char buf[5];
  while (*src && len != 0) {
    char16_t c = static_cast<char16_t>(dtohs(*src));
@@ -45,7 +41,6 @@ void ReadUtf16StringFromDevice(const uint16_t* src, size_t len, std::string* out
    --len;
  }
}
}

std::u16string Utf8ToUtf16(StringPiece utf8) {
  ssize_t utf16_length =
@@ -68,10 +63,8 @@ std::string Utf16ToUtf8(StringPiece16 utf16) {
  }

  std::string utf8;
  utf8.resize_and_overwrite(utf8_length, [&utf16](char* data, size_t size) {
    utf16_to_utf8(utf16.data(), utf16.length(), data, size + 1);
    return size;
  });
  utf8.resize(utf8_length);
  utf16_to_utf8(utf16.data(), utf16.length(), &*utf8.begin(), utf8_length + 1);
  return utf8;
}

+6 −42
Original line number Diff line number Diff line
@@ -47,8 +47,6 @@

namespace android {

constexpr const bool kDeviceEndiannessSame = dtohs(0x1001) == 0x1001;

constexpr const uint32_t kIdmapMagic = 0x504D4449u;
constexpr const uint32_t kIdmapCurrentVersion = 0x0000000Au;

@@ -410,16 +408,7 @@ struct Res_value
    typedef uint32_t data_type;
    data_type data;

    void copyFrom_dtoh(const Res_value& src) {
      if constexpr (kDeviceEndiannessSame) {
        *this = src;
      } else {
        copyFrom_dtoh_slow(src);
      }
    }

   private:
    void copyFrom_dtoh_slow(const Res_value& src);
    void copyFrom_dtoh(const Res_value& src);
};

/**
@@ -1265,32 +1254,11 @@ struct ResTable_config
    // Varies in length from 3 to 8 chars. Zero-filled value.
    char localeNumberingSystem[8];

    void copyFromDeviceNoSwap(const ResTable_config& o) {
      const auto o_size = dtohl(o.size);
      if (o_size >= sizeof(ResTable_config)) [[likely]] {
        *this = o;
      } else {
        memcpy(this, &o, o_size);
        memset(((uint8_t*)this) + o_size, 0, sizeof(ResTable_config) - o_size);
      }
      this->size = sizeof(*this);
    }
    void copyFromDeviceNoSwap(const ResTable_config& o);
    
    void copyFromDtoH(const ResTable_config& o) {
      if constexpr (kDeviceEndiannessSame) {
        copyFromDeviceNoSwap(o);
      } else {
        copyFromDtoH_slow(o);
      }
    }
    void copyFromDtoH(const ResTable_config& o);
    
    void swapHtoD() {
      if constexpr (kDeviceEndiannessSame) {
        ;  // noop
      } else {
        swapHtoD_slow();
      }
    }
    void swapHtoD();

    int compare(const ResTable_config& o) const;
    int compareLogical(const ResTable_config& o) const;
@@ -1416,10 +1384,6 @@ struct ResTable_config
    bool isBetterThanBeforeLocale(const ResTable_config& o, const ResTable_config* requested) const;

    String8 toString() const;

   private:
    void copyFromDtoH_slow(const ResTable_config& o);
    void swapHtoD_slow();
};

/**