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

Commit 356e28fd authored by Chris Jenneisch's avatar Chris Jenneisch Committed by Shuzhen Wang
Browse files

Use std::unordered_map for mTagToTypeMap

In the profile we notice that  SortedVectorImpl::_indexOrderOf is
almost 1.6% which is quite high considering it is an access to
a container. We make mTagToNameMap as a std::unordered_map
to store the Tag and the types. The accesses would be in constant time.

This change removes this from the profile and give ~10% improvement.

Bug: 72526772
Change-Id: Iffd244febd093bdfec9fe4d5e846a0e59c0ecdce
parent b21613bd
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -116,11 +116,11 @@ const char* VendorTagDescriptor::getTagName(uint32_t tag) const {
}

int VendorTagDescriptor::getTagType(uint32_t tag) const {
    ssize_t index = mTagToNameMap.indexOfKey(tag);
    if (index < 0) {
    auto iter = mTagToTypeMap.find(tag);
    if (iter == mTagToTypeMap.end()) {
        return VENDOR_TAG_TYPE_ERR;
    }
    return mTagToTypeMap.valueFor(tag);
    return iter->second;
}

const SortedVector<String8>* VendorTagDescriptor::getAllSectionNames() const {
@@ -167,7 +167,7 @@ void VendorTagDescriptor::dump(int fd, int verbosity, int indentation) const {
        String8 name = mTagToNameMap.valueAt(i);
        uint32_t sectionId = mTagToSectionMap.valueFor(tag);
        String8 sectionName = mSections[sectionId];
        int type = mTagToTypeMap.valueFor(tag);
        int type = mTagToTypeMap.at(tag);
        const char* typeName = (type >= 0 && type < NUM_TYPES) ?
                camera_metadata_type_names[type] : "UNKNOWN";
        dprintf(fd, "%*s0x%x (%s) with type %d (%s) defined in section %s\n", indentation + 2,
@@ -251,7 +251,7 @@ status_t VendorTagDescriptor::createDescriptorFromOps(const vendor_tag_ops_t* vO
            ALOGE("%s: tag type %d from vendor ops does not exist.", __FUNCTION__, tagType);
            return BAD_VALUE;
        }
        desc->mTagToTypeMap.add(tag, tagType);
        desc->mTagToTypeMap.insert(std::make_pair(tag, tagType));
    }

    desc->mSections = sections;
+3 −1
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@
#include <system/camera_vendor_tags.h>

#include <stdint.h>
#include <unordered_map>

namespace android {
namespace hardware {
@@ -94,7 +95,8 @@ class VendorTagDescriptor {
        KeyedVector<String8, KeyedVector<String8, uint32_t>*> mReverseMapping;
        KeyedVector<uint32_t, String8> mTagToNameMap;
        KeyedVector<uint32_t, uint32_t> mTagToSectionMap; // Value is offset in mSections
        KeyedVector<uint32_t, int32_t> mTagToTypeMap;

        std::unordered_map<uint32_t, int32_t> mTagToTypeMap;
        SortedVector<String8> mSections;
        // must be int32_t to be compatible with Parcel::writeInt32
        int32_t mTagCount;