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

Commit c62948ec authored by Siarhei Vishniakou's avatar Siarhei Vishniakou
Browse files

Return unique_ptr from readFromParcel

When KeyCharacterMap is read from parcel, there's no need to force the
caller to store the object in a shared pointer. We can return a
unique_ptr first, and let the caller decide on how exactly that lifetime
should be managed.

Bug: 274058082
Test: presubmit
Change-Id: I8c5ec1e32a9304f6ad186bc0279f4c7bcbab77d8
parent a5ac1e54
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -146,7 +146,7 @@ public:

#ifdef __linux__
    /* Reads a key map from a parcel. */
    static std::shared_ptr<KeyCharacterMap> readFromParcel(Parcel* parcel);
    static std::unique_ptr<KeyCharacterMap> readFromParcel(Parcel* parcel);

    /* Writes a key map to a parcel. */
    void writeToParcel(Parcel* parcel) const;
+3 −3
Original line number Diff line number Diff line
@@ -613,14 +613,14 @@ void KeyCharacterMap::addLockedMetaKey(Vector<KeyEvent>& outEvents,
}

#ifdef __linux__
std::shared_ptr<KeyCharacterMap> KeyCharacterMap::readFromParcel(Parcel* parcel) {
std::unique_ptr<KeyCharacterMap> KeyCharacterMap::readFromParcel(Parcel* parcel) {
    if (parcel == nullptr) {
        ALOGE("%s: Null parcel", __func__);
        return nullptr;
    }
    std::string loadFileName = parcel->readCString();
    std::shared_ptr<KeyCharacterMap> map =
            std::shared_ptr<KeyCharacterMap>(new KeyCharacterMap(loadFileName));
    std::unique_ptr<KeyCharacterMap> map =
            std::make_unique<KeyCharacterMap>(KeyCharacterMap(loadFileName));
    map->mType = static_cast<KeyCharacterMap::KeyboardType>(parcel->readInt32());
    map->mLayoutOverlayApplied = parcel->readBool();
    size_t numKeys = parcel->readInt32();