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

Commit 264fa4ce authored by Andy Hung's avatar Andy Hung
Browse files

AudioSystem: Modernize return value optimization

Storing sp<> return values in a const ref to temporary
seems like an outdated way to avoid an additional copy,
if that was indeed the original intention to optimize.

Avoid storing the sp<> return value in a const ref to avoid
confusion with returning a reference (which is dangerous
as it allows access without the lock). Instead store the
sp<> return value in a const lvalue to invoke copy elision
which is guaranteed in C++17.

Test: atest CtsMediaAudioTestCases
Bug: 326504627
Change-Id: I3e34f01be0d9b85289ff88e0bc289eec833b5348
parent acd955ac
Loading
Loading
Loading
Loading
+147 −148

File changed.

Preview size limit exceeded, changes collapsed.

+3 −3
Original line number Original line Diff line number Diff line
@@ -182,8 +182,8 @@ public:
    static status_t setLocalAudioFlinger(const sp<IAudioFlinger>& af);
    static status_t setLocalAudioFlinger(const sp<IAudioFlinger>& af);


    // helper function to obtain AudioFlinger service handle
    // helper function to obtain AudioFlinger service handle
    static const sp<IAudioFlinger> get_audio_flinger();
    static sp<IAudioFlinger> get_audio_flinger();
    static const sp<IAudioFlinger> get_audio_flinger_for_fuzzer();
    static sp<IAudioFlinger> get_audio_flinger_for_fuzzer();


    static float linearToLog(int volume);
    static float linearToLog(int volume);
    static int logToLinear(float volume);
    static int logToLinear(float volume);
@@ -407,7 +407,7 @@ public:
    // and output configuration cache (gOutputs)
    // and output configuration cache (gOutputs)
    static void clearAudioConfigCache();
    static void clearAudioConfigCache();


    static const sp<media::IAudioPolicyService> get_audio_policy_service();
    static sp<media::IAudioPolicyService> get_audio_policy_service();
    static void clearAudioPolicyService();
    static void clearAudioPolicyService();


    // helpers for android.media.AudioManager.getProperty(), see description there for meaning
    // helpers for android.media.AudioManager.getProperty(), see description there for meaning