diff options
author | 2025-01-08 05:57:41 -0800 | |
---|---|---|
committer | 2025-01-08 05:57:41 -0800 | |
commit | 6e4275255688ab4e7a0bc5602f4ba1ee2958cff4 (patch) | |
tree | 019cf2f0b57aa5f261ced736d5595a7697b2b034 /libs | |
parent | eb759ec58d1617699afa76f42a0965b41bab0bb2 (diff) |
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
Diffstat (limited to 'libs')
-rw-r--r-- | libs/androidfw/ResourceTypes.cpp | 78 | ||||
-rw-r--r-- | libs/androidfw/Util.cpp | 25 | ||||
-rw-r--r-- | libs/androidfw/include/androidfw/ResourceTypes.h | 48 |
3 files changed, 60 insertions, 91 deletions
diff --git a/libs/androidfw/ResourceTypes.cpp b/libs/androidfw/ResourceTypes.cpp index a8eb062a2ece..de9991a8be5e 100644 --- a/libs/androidfw/ResourceTypes.cpp +++ b/libs/androidfw/ResourceTypes.cpp @@ -152,11 +152,12 @@ 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) { - size = dtohs(src.size); - res0 = src.res0; - dataType = src.dataType; - data = dtohl(src.data); +void Res_value::copyFrom_dtoh(const Res_value& src) +{ + size = dtohs(src.size); + res0 = src.res0; + dataType = src.dataType; + data = dtohl(src.data); } void Res_png_9patch::deviceToFile() @@ -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,33 +2105,34 @@ size_t ResTable_config::unpackRegion(char region[4]) const { return unpackLanguageOrRegion(this->country, '0', region); } -void ResTable_config::copyFromDtoH_slow(const ResTable_config& o) { - copyFromDeviceNoSwap(o); - size = sizeof(ResTable_config); - mcc = dtohs(mcc); - mnc = dtohs(mnc); - density = dtohs(density); - screenWidth = dtohs(screenWidth); - screenHeight = dtohs(screenHeight); - sdkVersion = dtohs(sdkVersion); - minorVersion = dtohs(minorVersion); - smallestScreenWidthDp = dtohs(smallestScreenWidthDp); - screenWidthDp = dtohs(screenWidthDp); - screenHeightDp = dtohs(screenHeightDp); -} - -void ResTable_config::swapHtoD_slow() { - size = htodl(size); - mcc = htods(mcc); - mnc = htods(mnc); - density = htods(density); - screenWidth = htods(screenWidth); - screenHeight = htods(screenHeight); - sdkVersion = htods(sdkVersion); - minorVersion = htods(minorVersion); - smallestScreenWidthDp = htods(smallestScreenWidthDp); - screenWidthDp = htods(screenWidthDp); - screenHeightDp = htods(screenHeightDp); + +void ResTable_config::copyFromDtoH(const ResTable_config& o) { + copyFromDeviceNoSwap(o); + size = sizeof(ResTable_config); + mcc = dtohs(mcc); + mnc = dtohs(mnc); + density = dtohs(density); + screenWidth = dtohs(screenWidth); + screenHeight = dtohs(screenHeight); + sdkVersion = dtohs(sdkVersion); + minorVersion = dtohs(minorVersion); + smallestScreenWidthDp = dtohs(smallestScreenWidthDp); + screenWidthDp = dtohs(screenWidthDp); + screenHeightDp = dtohs(screenHeightDp); +} + +void ResTable_config::swapHtoD() { + size = htodl(size); + mcc = htods(mcc); + mnc = htods(mnc); + density = htods(density); + screenWidth = htods(screenWidth); + screenHeight = htods(screenHeight); + sdkVersion = htods(sdkVersion); + minorVersion = htods(minorVersion); + smallestScreenWidthDp = htods(smallestScreenWidthDp); + screenWidthDp = htods(screenWidthDp); + screenHeightDp = htods(screenHeightDp); } /* static */ inline int compareLocales(const ResTable_config &l, const ResTable_config &r) { @@ -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; diff --git a/libs/androidfw/Util.cpp b/libs/androidfw/Util.cpp index 86c459fb4647..be55fe8b4bb6 100644 --- a/libs/androidfw/Util.cpp +++ b/libs/androidfw/Util.cpp @@ -32,18 +32,13 @@ 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)); - utf16_to_utf8(&c, 1, buf, sizeof(buf)); - out->append(buf, strlen(buf)); - ++src; - --len; - } + char buf[5]; + while (*src && len != 0) { + char16_t c = static_cast<char16_t>(dtohs(*src)); + utf16_to_utf8(&c, 1, buf, sizeof(buf)); + out->append(buf, strlen(buf)); + ++src; + --len; } } @@ -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; } diff --git a/libs/androidfw/include/androidfw/ResourceTypes.h b/libs/androidfw/include/androidfw/ResourceTypes.h index 819fe4b38c87..e330410ed1a0 100644 --- a/libs/androidfw/include/androidfw/ResourceTypes.h +++ b/libs/androidfw/include/androidfw/ResourceTypes.h @@ -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 copyFromDtoH(const ResTable_config& o) { - if constexpr (kDeviceEndiannessSame) { - copyFromDeviceNoSwap(o); - } else { - copyFromDtoH_slow(o); - } - } - - void swapHtoD() { - if constexpr (kDeviceEndiannessSame) { - ; // noop - } else { - swapHtoD_slow(); - } - } + void copyFromDeviceNoSwap(const ResTable_config& o); + + void copyFromDtoH(const ResTable_config& o); + + 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(); }; /** |