OSDN Git Service

Fix clang-tidy performance warnings in audioservice.
authorChih-Hung Hsieh <chh@google.com>
Wed, 27 Jul 2016 21:44:07 +0000 (14:44 -0700)
committerChih-Hung Hsieh <chh@google.com>
Wed, 27 Jul 2016 21:44:07 +0000 (14:44 -0700)
* Use const reference type for parameters and
  for-loop index variables to avoid unnecessary copy.

Bug: 30407689
Bug: 30413223
Change-Id: Ie99f89ee67de9f2ace61f0971cd4a1820617f7d4
Test: build with WITH_TIDY=1

brillo/audio/audioservice/audio_service_callback.cpp
brillo/audio/audioservice/audio_service_callback.h
brillo/audio/audioservice/brillo_audio_client.cpp
brillo/audio/audioservice/brillo_audio_client.h
brillo/audio/audioservice/brillo_audio_service_impl.cpp

index eecc1ce..3baee23 100644 (file)
@@ -66,7 +66,7 @@ Status AudioServiceCallback::OnVolumeChanged(int stream,
   return Status::ok();
 }
 
-bool AudioServiceCallback::Equals(android::sp<AudioServiceCallback> callback) {
+bool AudioServiceCallback::Equals(const android::sp<AudioServiceCallback>& callback) {
   if (callback->connected_callback_.Equals(connected_callback_) &&
       callback->disconnected_callback_.Equals(disconnected_callback_) &&
       callback->volume_callback_.Equals(volume_callback_) &&
index 5c72924..3a5a289 100644 (file)
@@ -62,7 +62,7 @@ class AudioServiceCallback : public BnAudioServiceCallback {
   // compared with this.
   //
   // Returns true if |callback| equals this.
-  bool Equals(android::sp<AudioServiceCallback> callback);
+  bool Equals(const android::sp<AudioServiceCallback>& callback);
 
  private:
   // Callback when devices are connected.
index 4f162be..f347c56 100644 (file)
@@ -51,7 +51,7 @@ std::weak_ptr<BrilloAudioClient> BrilloAudioClient::GetClientInstance() {
 }
 
 android::sp<android::IBinder> BrilloAudioClient::ConnectToService(
-    std::string service_name, const base::Closure& callback) {
+    const std::string& service_name, const base::Closure& callback) {
   android::BinderWrapper* binder_wrapper =
       android::BinderWrapper::GetOrCreateInstance();
   auto service = binder_wrapper->GetService(service_name);
index d7e31f1..00c431a 100644 (file)
@@ -160,7 +160,7 @@ class BrilloAudioClient {
   //
   // |service_name| is a string representing the name of the service.
   // |callback| is a base::Closure which will be called if the service dies.
-  android::sp<android::IBinder> ConnectToService(std::string service_name,
+  android::sp<android::IBinder> ConnectToService(const std::string& service_name,
                                                  const base::Closure& callback);
 
   // Pointer to the BrilloAudioClient object.
index d108a4a..1585755 100644 (file)
@@ -170,14 +170,14 @@ Status BrilloAudioServiceImpl::DecrementVolume() {
 
 void BrilloAudioServiceImpl::OnDevicesConnected(
     const std::vector<int>& devices) {
-  for (auto callback : callbacks_set_) {
+  for (const auto& callback : callbacks_set_) {
     callback->OnAudioDevicesConnected(devices);
   }
 }
 
 void BrilloAudioServiceImpl::OnDevicesDisconnected(
     const std::vector<int>& devices) {
-  for (auto callback : callbacks_set_) {
+  for (const auto& callback : callbacks_set_) {
     callback->OnAudioDevicesDisconnected(devices);
   }
 }
@@ -185,7 +185,7 @@ void BrilloAudioServiceImpl::OnDevicesDisconnected(
 void BrilloAudioServiceImpl::OnVolumeChanged(audio_stream_type_t stream,
                                              int previous_index,
                                              int current_index) {
-  for (auto callback : callbacks_set_) {
+  for (const auto& callback : callbacks_set_) {
     callback->OnVolumeChanged(stream, previous_index, current_index);
   }
 }