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

Commit 49ca8f19 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge changes Ifd2c12c7,I8aae2a3c into main

* changes:
  [res] Optimize locale comparison and alias search
  [res] Move the latin parents map to be first
parents 6ae80c5b 85e49ba0
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -2451,10 +2451,10 @@ const struct {
    const char script[4];
    const std::unordered_map<uint32_t, uint32_t>* map;
} SCRIPT_PARENTS[] = {
    {{'L', 'a', 't', 'n'}, &LATN_PARENTS},
    {{'A', 'r', 'a', 'b'}, &ARAB_PARENTS},
    {{'D', 'e', 'v', 'a'}, &DEVA_PARENTS},
    {{'H', 'a', 'n', 't'}, &HANT_PARENTS},
    {{'L', 'a', 't', 'n'}, &LATN_PARENTS},
    {{'~', '~', '~', 'B'}, &___B_PARENTS},
};

+22 −19
Original line number Diff line number Diff line
@@ -2650,8 +2650,9 @@ bool ResTable_config::isBetterThan(const ResTable_config& o,
                return (mnc);
            }
        }

        if (isLocaleBetterThan(o, requested)) {
        // Cheaper to check for the empty locales here before calling the function
        // as we often can skip it completely.
        if (requested->locale && (locale || o.locale) && isLocaleBetterThan(o, requested)) {
            return true;
        }

@@ -7237,37 +7238,39 @@ void DynamicRefTable::addMapping(uint8_t buildPackageId, uint8_t runtimePackageI

status_t DynamicRefTable::lookupResourceId(uint32_t* resId) const {
    uint32_t res = *resId;
    size_t packageId = Res_GETPACKAGE(res) + 1;

    if (!Res_VALIDID(res)) {
        // Cannot look up a null or invalid id, so no lookup needs to be done.
        return NO_ERROR;
    }

    const size_t packageId = Res_GETPACKAGE(res) + 1;
    if (packageId == 0 || (packageId == APP_PACKAGE_ID && mAppAsLib)) {
        // The package ID is 0x00. That means that a shared library is accessing
        // its own local resource.
        // Or if app resource is loaded as shared library, the resource which has
        // app package Id is local resources.
        // so we fix up those resources with the calling package ID.
        *resId = (0xFFFFFF & (*resId)) | (((uint32_t) mAssignedPackageId) << 24);
        return NO_ERROR;
    }
    // All aliases are coming from the framework, and usually have their own separate ID range,
    // skipping the whole binary search is much more efficient than not finding anything.
    if (packageId == SYS_PACKAGE_ID && !mAliasId.empty() &&
            res >= mAliasId.front().first && res <= mAliasId.back().first) {
        const auto alias_it = std::lower_bound(mAliasId.begin(), mAliasId.end(), res,
        [](const AliasMap::value_type& pair, uint32_t val) { return pair.first < val; });
                                               [](const AliasMap::value_type& pair,
                                                  uint32_t val) { return pair.first < val; });
        if (alias_it != mAliasId.end() && alias_it->first == res) {
            // Rewrite the resource id to its alias resource id. Since the alias resource id is a
            // compile-time id, it still needs to be resolved further.
            res = alias_it->second;
        }

    }
    if (packageId == SYS_PACKAGE_ID || (packageId == APP_PACKAGE_ID && !mAppAsLib)) {
        // No lookup needs to be done, app and framework package IDs are absolute.
        *resId = res;
        return NO_ERROR;
    }

    if (packageId == 0 || (packageId == APP_PACKAGE_ID && mAppAsLib)) {
        // The package ID is 0x00. That means that a shared library is accessing
        // its own local resource.
        // Or if app resource is loaded as shared library, the resource which has
        // app package Id is local resources.
        // so we fix up those resources with the calling package ID.
        *resId = (0xFFFFFF & (*resId)) | (((uint32_t) mAssignedPackageId) << 24);
        return NO_ERROR;
    }

    // Do a proper lookup.
    uint8_t translatedId = mLookupTable[packageId];
    if (translatedId == 0) {