diff options
author | Chih-Hung Hsieh <chh@google.com> | 2016-07-28 12:23:20 -0700 |
---|---|---|
committer | Chih-Hung Hsieh <chh@google.com> | 2016-07-28 13:38:06 -0700 |
commit | ec5aa476af8904680a7ffc461d4019d9c669bc04 (patch) | |
tree | c7fb963c8b3d3474d04db9983d408c81665bad3c | |
parent | 530fe47029e0128f3d4d1ee26a8ac8dfaf21aa90 (diff) | |
download | shill-ec5aa476af8904680a7ffc461d4019d9c669bc04.tar.gz |
Fix clang-tidy performance warnings in shill.
* Use const reference type for parameters, local variables,
and for-loop index variables to avoid unnecessary copy.
Bug: 30407689
Bug: 30413223
Bug: 30413862
Change-Id: Ib6b5f11086d07f39b924f748ea44c15b82d83d23
43 files changed, 110 insertions, 110 deletions
diff --git a/connection_health_checker.cc b/connection_health_checker.cc index 9291e572..7626e45e 100644 --- a/connection_health_checker.cc +++ b/connection_health_checker.cc @@ -127,7 +127,7 @@ bool ConnectionHealthChecker::health_check_in_progress() const { return health_check_in_progress_; } -void ConnectionHealthChecker::AddRemoteIP(IPAddress ip) { +void ConnectionHealthChecker::AddRemoteIP(const IPAddress& ip) { remote_ips_->AddUnique(ip); } @@ -206,7 +206,7 @@ void ConnectionHealthChecker::Stop() { num_tx_queue_polling_attempts_ = 0; } -void ConnectionHealthChecker::SetConnection(ConnectionRefPtr connection) { +void ConnectionHealthChecker::SetConnection(const ConnectionRefPtr& connection) { SLOG(connection_.get(), 3) << __func__; connection_ = connection; tcp_connection_.reset(new AsyncConnection(connection_->interface_name(), diff --git a/connection_health_checker.h b/connection_health_checker.h index 791d7a5f..6208fa5c 100644 --- a/connection_health_checker.h +++ b/connection_health_checker.h @@ -77,12 +77,12 @@ class ConnectionHealthChecker { // Name resolution can fail in conditions -(1)- and -(2)-. Add an IP address // to attempt the TCP connection with. - virtual void AddRemoteIP(IPAddress ip); + virtual void AddRemoteIP(const IPAddress& ip); // Change the associated Connection on the Device. // This will restart any ongoing health check. Any ongoing DNS query will be // dropped (not restarted). - virtual void SetConnection(ConnectionRefPtr connection); + virtual void SetConnection(const ConnectionRefPtr& connection); // Start a connection health check. The health check involves one or more // attempts at establishing and using a TCP connection. |result_callback_| is diff --git a/connection_health_checker_unittest.cc b/connection_health_checker_unittest.cc index 3a8edaf3..09ca0596 100644 --- a/connection_health_checker_unittest.cc +++ b/connection_health_checker_unittest.cc @@ -256,7 +256,7 @@ class ConnectionHealthCheckerTest : public Test { // This only works if GetSocketInfo is called with kProxyFD. // If no matching sock_info is provided (Does not belong to proxy socket), // GetSocketInfo will (correctly) return false. - void ExpectGetSocketInfoReturns(SocketInfo sock_info) { + void ExpectGetSocketInfoReturns(const SocketInfo& sock_info) { vector<SocketInfo> info_list; info_list.push_back(sock_info); EXPECT_CALL(*socket_, GetSockName(kProxyFD, _, _)) diff --git a/connection_info_unittest.cc b/connection_info_unittest.cc index c1b182d9..09634d1e 100644 --- a/connection_info_unittest.cc +++ b/connection_info_unittest.cc @@ -75,7 +75,7 @@ TEST_F(ConnectionInfoTest, CopyConstructor) { ByteString(kIPAddress4, sizeof(kIPAddress4))), kPort4); - ConnectionInfo info_copy(info); + const ConnectionInfo& info_copy(info); ExpectConnectionInfoEqual(info, info_copy); } @@ -96,7 +96,7 @@ TEST_F(ConnectionInfoTest, AssignmentOperator) { ByteString(kIPAddress4, sizeof(kIPAddress4))), kPort4); - ConnectionInfo info_copy = info; + const ConnectionInfo& info_copy = info; ExpectConnectionInfoEqual(info, info_copy); } diff --git a/connection_unittest.cc b/connection_unittest.cc index db4ee3ed..7fe25568 100644 --- a/connection_unittest.cc +++ b/connection_unittest.cc @@ -123,7 +123,7 @@ class ConnectionTest : public Test { connection_ = nullptr; } - void ReplaceSingletons(ConnectionRefPtr connection) { + void ReplaceSingletons(const ConnectionRefPtr& connection) { #if !defined(__ANDROID__) connection->resolver_ = &resolver_; #else @@ -141,21 +141,21 @@ class ConnectionTest : public Test { ip6config_->UpdateProperties(ipv6_properties_, true); } - bool PinHostRoute(ConnectionRefPtr connection, - const IPAddress trusted_ip, - const IPAddress gateway) { + bool PinHostRoute(const ConnectionRefPtr& connection, + const IPAddress& trusted_ip, + const IPAddress& gateway) { return connection->PinHostRoute(trusted_ip, gateway); } - const IPAddress& GetLocalAddress(ConnectionRefPtr connection) { + const IPAddress& GetLocalAddress(const ConnectionRefPtr& connection) { return connection->local_; } - const IPAddress& GetGatewayAddress(ConnectionRefPtr connection) { + const IPAddress& GetGatewayAddress(const ConnectionRefPtr& connection) { return connection->gateway_; } - bool GetHasBroadcastDomain(ConnectionRefPtr connection) { + bool GetHasBroadcastDomain(const ConnectionRefPtr& connection) { return connection->has_broadcast_domain_; } diff --git a/crypto_util_proxy_unittest.cc b/crypto_util_proxy_unittest.cc index d942f98f..8e7e3987 100644 --- a/crypto_util_proxy_unittest.cc +++ b/crypto_util_proxy_unittest.cc @@ -105,7 +105,7 @@ class CryptoUtilProxyTest : public testing::Test { pid_t HandleStartInMinijailWithPipes( const tracked_objects::Location& /* spawn_source */, const base::FilePath& /* program */, - vector<string> /* program_args */, + const vector<string>& /* program_args */, const std::string& /* run_as_user */, const std::string& /* run_as_group */, uint64_t /* capabilities_mask */, diff --git a/dbus/chromeos_manager_dbus_adaptor.cc b/dbus/chromeos_manager_dbus_adaptor.cc index 0aea07ea..0762ad6d 100644 --- a/dbus/chromeos_manager_dbus_adaptor.cc +++ b/dbus/chromeos_manager_dbus_adaptor.cc @@ -49,7 +49,7 @@ const char ChromeosManagerDBusAdaptor::kPath[] = "/"; ChromeosManagerDBusAdaptor::ChromeosManagerDBusAdaptor( const scoped_refptr<dbus::Bus>& adaptor_bus, - const scoped_refptr<dbus::Bus> proxy_bus, + const scoped_refptr<dbus::Bus>& proxy_bus, Manager* manager) : org::chromium::flimflam::ManagerAdaptor(this), ChromeosDBusAdaptor(adaptor_bus, kPath), diff --git a/dbus/chromeos_manager_dbus_adaptor.h b/dbus/chromeos_manager_dbus_adaptor.h index aa6278f0..1ab4caf3 100644 --- a/dbus/chromeos_manager_dbus_adaptor.h +++ b/dbus/chromeos_manager_dbus_adaptor.h @@ -48,7 +48,7 @@ class ChromeosManagerDBusAdaptor static const char kPath[]; ChromeosManagerDBusAdaptor(const scoped_refptr<dbus::Bus>& adaptor_bus, - const scoped_refptr<dbus::Bus> proxy_bus, + const scoped_refptr<dbus::Bus>& proxy_bus, Manager* manager); ~ChromeosManagerDBusAdaptor() override; diff --git a/dbus/dbus_service_watcher_factory.cc b/dbus/dbus_service_watcher_factory.cc index 2493703a..3036add5 100644 --- a/dbus/dbus_service_watcher_factory.cc +++ b/dbus/dbus_service_watcher_factory.cc @@ -33,7 +33,7 @@ DBusServiceWatcherFactory* DBusServiceWatcherFactory::GetInstance() { } ChromeosDBusServiceWatcher* DBusServiceWatcherFactory::CreateDBusServiceWatcher( - scoped_refptr<dbus::Bus> bus, const std::string& connection_name, + const scoped_refptr<dbus::Bus>& bus, const std::string& connection_name, const base::Closure& on_connection_vanish) { return new ChromeosDBusServiceWatcher(bus, connection_name, on_connection_vanish); diff --git a/dbus/dbus_service_watcher_factory.h b/dbus/dbus_service_watcher_factory.h index f005d160..14bffe8c 100644 --- a/dbus/dbus_service_watcher_factory.h +++ b/dbus/dbus_service_watcher_factory.h @@ -36,7 +36,7 @@ class DBusServiceWatcherFactory { static DBusServiceWatcherFactory* GetInstance(); virtual ChromeosDBusServiceWatcher* CreateDBusServiceWatcher( - scoped_refptr<dbus::Bus> bus, const std::string& connection_name, + const scoped_refptr<dbus::Bus>& bus, const std::string& connection_name, const base::Closure& on_connection_vanish); protected: diff --git a/dbus/mock_dbus_service_watcher_factory.h b/dbus/mock_dbus_service_watcher_factory.h index 00194f0f..ebf81265 100644 --- a/dbus/mock_dbus_service_watcher_factory.h +++ b/dbus/mock_dbus_service_watcher_factory.h @@ -30,7 +30,7 @@ class MockDBusServiceWatcherFactory : public DBusServiceWatcherFactory { MOCK_METHOD3( CreateDBusServiceWatcher, - ChromeosDBusServiceWatcher*(scoped_refptr<dbus::Bus> bus, + ChromeosDBusServiceWatcher*(const scoped_refptr<dbus::Bus>& bus, const std::string& connection_name, const base::Closure& on_connection_vanish)); diff --git a/device_unittest.cc b/device_unittest.cc index 82da3fe0..e7be6f6c 100644 --- a/device_unittest.cc +++ b/device_unittest.cc @@ -211,11 +211,11 @@ class DeviceTest : public PropertyStoreTest { device_->OnIPConfigExpired(ipconfig); } - void SelectService(const ServiceRefPtr service) { + void SelectService(const ServiceRefPtr& service) { device_->SelectService(service); } - void SetConnection(ConnectionRefPtr connection) { + void SetConnection(const ConnectionRefPtr& connection) { device_->connection_ = connection; } @@ -2666,7 +2666,7 @@ class DeviceByteCountTest : public DeviceTest { return true; } - bool ExpectByteCounts(DeviceRefPtr device, + bool ExpectByteCounts(const DeviceRefPtr& device, int64_t expected_rx, int64_t expected_tx) { int64_t actual_rx = device->GetReceiveByteCount(); int64_t actual_tx = device->GetTransmitByteCount(); @@ -2675,7 +2675,7 @@ class DeviceByteCountTest : public DeviceTest { return expected_rx == actual_rx && expected_tx == actual_tx; } - void ExpectSavedCounts(DeviceRefPtr device, + void ExpectSavedCounts(const DeviceRefPtr& device, int64_t expected_rx, int64_t expected_tx) { EXPECT_CALL(storage_, SetUint64(_, Device::kStorageReceiveByteCount, expected_rx)) diff --git a/dhcp/dhcpv4_config.cc b/dhcp/dhcpv4_config.cc index 1d3411f0..d62a7433 100644 --- a/dhcp/dhcpv4_config.cc +++ b/dhcp/dhcpv4_config.cc @@ -343,7 +343,7 @@ bool DHCPv4Config::ParseConfiguration(const KeyValueStore& configuration, properties->address_family = IPAddress::kFamilyIPv4; string classless_static_routes; bool default_gateway_parse_error = false; - for (const auto it : configuration.properties()) { + for (const auto& it : configuration.properties()) { const string& key = it.first; const brillo::Any& value = it.second; SLOG(nullptr, 2) << "Processing key: " << key; diff --git a/dhcp/dhcpv4_config_unittest.cc b/dhcp/dhcpv4_config_unittest.cc index ebe607a9..7ac534af 100644 --- a/dhcp/dhcpv4_config_unittest.cc +++ b/dhcp/dhcpv4_config_unittest.cc @@ -93,7 +93,7 @@ class DHCPv4ConfigTest : public PropertyStoreTest { config_->process_manager_ = &process_manager_; } - bool StartInstance(DHCPv4ConfigRefPtr config) { + bool StartInstance(const DHCPv4ConfigRefPtr& config) { return config->Start(); } @@ -109,7 +109,7 @@ class DHCPv4ConfigTest : public PropertyStoreTest { const string& vendorclass, const string& lease_suffix, bool arp_gateway); - void StopRunningConfigAndExpect(DHCPv4ConfigRefPtr config, + void StopRunningConfigAndExpect(const DHCPv4ConfigRefPtr& config, bool lease_file_exists); protected: @@ -222,7 +222,7 @@ DHCPv4ConfigRefPtr DHCPv4ConfigTest::CreateRunningConfig( return config; } -void DHCPv4ConfigTest::StopRunningConfigAndExpect(DHCPv4ConfigRefPtr config, +void DHCPv4ConfigTest::StopRunningConfigAndExpect(const DHCPv4ConfigRefPtr& config, bool lease_file_exists) { ScopedMockLog log; // We use a non-zero exit status so that we get the log message. @@ -1662,8 +1662,8 @@ void Manager::VerifyAndEncryptCredentials(const string& certificate, } #endif // DISABLE_WIFI -int Manager::CalcConnectionId(std::string gateway_ip, - std::string gateway_mac) { +int Manager::CalcConnectionId(const std::string& gateway_ip, + const std::string& gateway_mac) { return static_cast<int>(std::hash<std::string>()(gateway_ip + gateway_mac + std::to_string(props_.connection_id_salt))); } @@ -2532,8 +2532,8 @@ ServiceRefPtr Manager::ConfigureServiceForProfile( return nullptr; } -void Manager::SetupServiceInProfile(ServiceRefPtr service, - ProfileRefPtr profile, +void Manager::SetupServiceInProfile(const ServiceRefPtr& service, + const ProfileRefPtr& profile, const KeyValueStore& args, Error* error) { service->SetProfile(profile); @@ -2672,7 +2672,7 @@ void Manager::UpdateProviderMapping() { #endif // DISABLE_WIMAX } -DeviceRefPtr Manager::GetDeviceConnectedToService(ServiceRefPtr service) { +DeviceRefPtr Manager::GetDeviceConnectedToService(const ServiceRefPtr& service) { for (DeviceRefPtr device : devices_) { if (device->IsConnectedToService(service)) { return device; @@ -505,7 +505,7 @@ class Manager : public base::SupportsWeakPtr<Manager> { // Calculate connection identifier, which is hash of salt value, gateway IP // address, and gateway MAC address. - int CalcConnectionId(std::string gateway_ip, std::string gateway_mac); + int CalcConnectionId(const std::string& gateway_ip, const std::string& gateway_mac); // Report the number of services associated with given connection // |connection_id|. @@ -734,8 +734,8 @@ class Manager : public base::SupportsWeakPtr<Manager> { // the resulting configuration to |profile|. This method is useful // when copying a service configuration from one profile to another, // or writing a newly created service config to a specific profile. - static void SetupServiceInProfile(ServiceRefPtr service, - ProfileRefPtr profile, + static void SetupServiceInProfile(const ServiceRefPtr& service, + const ProfileRefPtr& profile, const KeyValueStore& args, Error* error); @@ -787,7 +787,7 @@ class Manager : public base::SupportsWeakPtr<Manager> { power_manager_.reset(power_manager); } - DeviceRefPtr GetDeviceConnectedToService(ServiceRefPtr service); + DeviceRefPtr GetDeviceConnectedToService(const ServiceRefPtr& service); void DeregisterDeviceByLinkName(const std::string& link_name); diff --git a/manager_unittest.cc b/manager_unittest.cc index fbed9678..2de1d52e 100644 --- a/manager_unittest.cc +++ b/manager_unittest.cc @@ -202,9 +202,9 @@ class ManagerTest : public PropertyStoreTest { auto devices = manager()->FilterByTechnology(tech); return (devices.size() == 1 && devices[0].get() == device.get()); } - bool ServiceOrderIs(ServiceRefPtr svc1, ServiceRefPtr svc2); + bool ServiceOrderIs(const ServiceRefPtr& svc1, const ServiceRefPtr& svc2); - void AdoptProfile(Manager* manager, ProfileRefPtr profile) { + void AdoptProfile(Manager* manager, const ProfileRefPtr& profile) { manager->profiles_.push_back(profile); } @@ -518,7 +518,7 @@ class ManagerTest : public PropertyStoreTest { const char ManagerTest::TerminationActionTest::kActionName[] = "action"; -bool ManagerTest::ServiceOrderIs(ServiceRefPtr svc0, ServiceRefPtr svc1) { +bool ManagerTest::ServiceOrderIs(const ServiceRefPtr& svc0, const ServiceRefPtr& svc1) { if (!manager()->sort_services_task_.IsCancelled()) { manager()->SortServicesTask(); } diff --git a/mock_connection_health_checker.h b/mock_connection_health_checker.h index 062c6bb1..fc2a3997 100644 --- a/mock_connection_health_checker.h +++ b/mock_connection_health_checker.h @@ -35,7 +35,7 @@ class MockConnectionHealthChecker : public ConnectionHealthChecker { ~MockConnectionHealthChecker() override; MOCK_METHOD1(AddRemoteURL, void(const std::string& url_string)); - MOCK_METHOD1(AddRemoteIP, void(IPAddress ip)); + MOCK_METHOD1(AddRemoteIP, void(const IPAddress& ip)); MOCK_METHOD0(Start, void()); MOCK_METHOD0(Stop, void()); MOCK_CONST_METHOD0(health_check_in_progress, bool()); diff --git a/net/attribute_list.cc b/net/attribute_list.cc index 6065c49f..e0844a7f 100644 --- a/net/attribute_list.cc +++ b/net/attribute_list.cc @@ -38,7 +38,7 @@ using std::string; namespace shill { bool AttributeList::CreateAttribute( - int id, AttributeList::NewFromIdMethod factory) { + int id, const AttributeList::NewFromIdMethod& factory) { if (ContainsKey(attributes_, id)) { VLOG(7) << "Trying to re-add attribute " << id << ", not overwriting"; return true; @@ -300,7 +300,7 @@ bool AttributeList::CreateSsidAttribute(int id, const char* id_string) { return true; } -bool AttributeList::SetStringAttributeValue(int id, string value) { +bool AttributeList::SetStringAttributeValue(int id, const string& value) { NetlinkAttribute* attribute = GetAttribute(id); if (!attribute) return false; @@ -361,7 +361,7 @@ bool AttributeList::GetRawAttributeValue(int id, return true; } -bool AttributeList::SetRawAttributeValue(int id, ByteString value) { +bool AttributeList::SetRawAttributeValue(int id, const ByteString& value) { NetlinkAttribute* attribute = GetAttribute(id); if (!attribute) return false; diff --git a/net/attribute_list.h b/net/attribute_list.h index 18f325bf..6d1a45d0 100644 --- a/net/attribute_list.h +++ b/net/attribute_list.h @@ -49,7 +49,7 @@ class SHILL_EXPORT AttributeList : public base::RefCounted<AttributeList> { // Instantiates an NetlinkAttribute of the appropriate type from |id|, // and adds it to |attributes_|. - bool CreateAttribute(int id, NewFromIdMethod factory); + bool CreateAttribute(int id, const NewFromIdMethod& factory); // Helper function for creating control attribute. bool CreateControlAttribute(int id); @@ -117,7 +117,7 @@ class SHILL_EXPORT AttributeList : public base::RefCounted<AttributeList> { bool CreateStringAttribute(int id, const char* id_string); // SSID attributes are derived from string attributes. bool CreateSsidAttribute(int id, const char* id_string); - bool SetStringAttributeValue(int id, std::string value); + bool SetStringAttributeValue(int id, const std::string& value); bool GetStringAttributeValue(int id, std::string* value) const; bool CreateNestedAttribute(int id, const char* id_string); @@ -129,7 +129,7 @@ class SHILL_EXPORT AttributeList : public base::RefCounted<AttributeList> { bool CreateRawAttribute(int id, const char* id_string); // |value| should point to the data (after the |nlattr| header, if there is // one). - bool SetRawAttributeValue(int id, ByteString value); + bool SetRawAttributeValue(int id, const ByteString& value); bool GetRawAttributeValue(int id, ByteString* output) const; // This retrieves a string from any kind of attribute. diff --git a/net/event_history.cc b/net/event_history.cc index cd269f74..c0992853 100644 --- a/net/event_history.cc +++ b/net/event_history.cc @@ -50,7 +50,7 @@ std::vector<std::string> EventHistory::ExtractWallClockToStrings() const { return strings; } -void EventHistory::RecordEventInternal(Timestamp now) { +void EventHistory::RecordEventInternal(const Timestamp& now) { events_.push_back(now); while (!events_.empty() && max_events_specified_ && (events_.size() > static_cast<size_t>(max_events_saved_))) { diff --git a/net/event_history.h b/net/event_history.h index 615262d9..9b2ac878 100644 --- a/net/event_history.h +++ b/net/event_history.h @@ -82,7 +82,7 @@ class SHILL_EXPORT EventHistory { friend class ServiceTest; // RecordEventInternal, time_ friend class WakeOnWiFiTest; // time_ - void RecordEventInternal(Timestamp now); + void RecordEventInternal(const Timestamp& now); void ExpireEventsBeforeInternal(int seconds_ago, Timestamp now, ClockType clock_type); diff --git a/net/event_history_unittest.cc b/net/event_history_unittest.cc index fe4eb15d..80c8f54a 100644 --- a/net/event_history_unittest.cc +++ b/net/event_history_unittest.cc @@ -61,18 +61,18 @@ class EventHistoryTest : public ::testing::Test { deque<Timestamp>* GetEvents() { return &event_history_->events_; } - void RecordEvent(Timestamp now) { + void RecordEvent(const Timestamp& now) { EXPECT_CALL(time_, GetNow()).WillOnce(Return(now)); event_history_->RecordEvent(); } - void ExpireEventsBefore(int seconds_ago, Timestamp now, + void ExpireEventsBefore(int seconds_ago, const Timestamp& now, EventHistory::ClockType clock_type) { EXPECT_CALL(time_, GetNow()).WillOnce(Return(now)); event_history_->ExpireEventsBefore(seconds_ago, clock_type); } - void RecordEventAndExpireEventsBefore(int seconds_ago, Timestamp now, + void RecordEventAndExpireEventsBefore(int seconds_ago, const Timestamp& now, EventHistory::ClockType clock_type) { EXPECT_CALL(time_, GetNow()).WillOnce(Return(now)); event_history_->RecordEventAndExpireEventsBefore(seconds_ago, clock_type); @@ -91,7 +91,7 @@ class EventHistoryTest : public ::testing::Test { int CountEventsWithinInterval(int seconds_ago, EventHistory::ClockType clock_type, - Timestamp now) { + const Timestamp& now) { EXPECT_CALL(time_, GetNow()).WillOnce(Return(now)); return event_history_->CountEventsWithinInterval(seconds_ago, clock_type); } diff --git a/net/netlink_attribute.cc b/net/netlink_attribute.cc index 3248a499..2d3d1955 100644 --- a/net/netlink_attribute.cc +++ b/net/netlink_attribute.cc @@ -356,7 +356,7 @@ bool NetlinkAttribute::GetStringValue(string* value) const { return false; } -bool NetlinkAttribute::SetStringValue(string value) { +bool NetlinkAttribute::SetStringValue(const string& value) { LOG(ERROR) << "Attribute is not of type 'String'"; return false; } @@ -382,7 +382,7 @@ bool NetlinkAttribute::GetRawValue(ByteString* value) const { return false; } -bool NetlinkAttribute::SetRawValue(const ByteString new_value) { +bool NetlinkAttribute::SetRawValue(const ByteString& new_value) { LOG(ERROR) << "Attribute is not of type 'Raw'"; return false; } @@ -745,7 +745,7 @@ bool NetlinkStringAttribute::GetStringValue(string* output) const { return true; } -bool NetlinkStringAttribute::SetStringValue(const string new_value) { +bool NetlinkStringAttribute::SetStringValue(const string& new_value) { value_ = new_value; has_a_value_ = true; return true; @@ -1049,7 +1049,7 @@ bool NetlinkRawAttribute::GetRawValue(ByteString* output) const { return true; } -bool NetlinkRawAttribute::SetRawValue(const ByteString new_value) { +bool NetlinkRawAttribute::SetRawValue(const ByteString& new_value) { data_ = new_value; has_a_value_ = true; return true; diff --git a/net/netlink_attribute.h b/net/netlink_attribute.h index b1ab1500..2736c642 100644 --- a/net/netlink_attribute.h +++ b/net/netlink_attribute.h @@ -90,7 +90,7 @@ class SHILL_EXPORT NetlinkAttribute { virtual bool SetFlagValue(bool value); virtual bool GetStringValue(std::string* value) const; - virtual bool SetStringValue(const std::string value); + virtual bool SetStringValue(const std::string& value); virtual bool GetNestedAttributeList(AttributeListRefPtr* value); virtual bool ConstGetNestedAttributeList( @@ -98,7 +98,7 @@ class SHILL_EXPORT NetlinkAttribute { virtual bool SetNestedHasAValue(); virtual bool GetRawValue(ByteString* value) const; - virtual bool SetRawValue(const ByteString value); + virtual bool SetRawValue(const ByteString& value); // Prints the attribute info -- for debugging. virtual void Print(int log_level, int indent) const; @@ -243,7 +243,7 @@ class SHILL_EXPORT NetlinkStringAttribute : public NetlinkAttribute { : NetlinkAttribute(id, id_string, kType, kMyTypeString) {} virtual bool InitFromValue(const ByteString& data); virtual bool GetStringValue(std::string* value) const; - virtual bool SetStringValue(const std::string new_value); + virtual bool SetStringValue(const std::string& new_value); virtual bool ToString(std::string* value) const; virtual ByteString Encode() const; std::string value() const { return value_; } @@ -292,7 +292,7 @@ class NetlinkNestedAttribute : public NetlinkAttribute { struct NestedData { typedef base::Callback<bool (AttributeList* list, size_t id, const std::string& attribute_name, - ByteString data)> AttributeParser; + const ByteString& data)> AttributeParser; typedef std::map<size_t, NestedData> NestedDataMap; NestedData(); @@ -369,7 +369,7 @@ class NetlinkRawAttribute : public NetlinkAttribute { // Gets the value of the data (the header is not stored). virtual bool GetRawValue(ByteString* value) const; // Should set the value of the data (not the attribute header). - virtual bool SetRawValue(const ByteString value); + virtual bool SetRawValue(const ByteString& value); virtual bool ToString(std::string* value) const; virtual ByteString Encode() const; diff --git a/net/netlink_message.cc b/net/netlink_message.cc index 752f0984..a4469a38 100644 --- a/net/netlink_message.cc +++ b/net/netlink_message.cc @@ -267,7 +267,7 @@ void UnknownMessage::Print(int header_log_level, // bool NetlinkMessageFactory::AddFactoryMethod(uint16_t message_type, - FactoryMethod factory) { + const FactoryMethod& factory) { if (ContainsKey(factories_, message_type)) { LOG(WARNING) << "Message type " << message_type << " already exists."; return false; diff --git a/net/netlink_message.h b/net/netlink_message.h index 5a879549..37e84c73 100644 --- a/net/netlink_message.h +++ b/net/netlink_message.h @@ -243,7 +243,7 @@ class SHILL_EXPORT NetlinkMessageFactory { // Adds a message factory for a specific message_type. Intended to be used // at initialization. - bool AddFactoryMethod(uint16_t message_type, FactoryMethod factory); + bool AddFactoryMethod(uint16_t message_type, const FactoryMethod& factory); // Ownership of the message is passed to the caller and, as such, he should // delete it. diff --git a/net/nl80211_attribute.cc b/net/nl80211_attribute.cc index 89600c15..54b5877f 100644 --- a/net/nl80211_attribute.cc +++ b/net/nl80211_attribute.cc @@ -123,7 +123,7 @@ Nl80211AttributeBss::Nl80211AttributeBss() bool Nl80211AttributeBss::ParseInformationElements( AttributeList* attribute_list, size_t id, const string& attribute_name, - ByteString data) { + const ByteString& data) { if (!attribute_list) { LOG(ERROR) << "NULL |attribute_list| parameter"; return false; diff --git a/net/nl80211_attribute.h b/net/nl80211_attribute.h index b9a793a9..71c0e7a3 100644 --- a/net/nl80211_attribute.h +++ b/net/nl80211_attribute.h @@ -581,7 +581,7 @@ class Nl80211AttributeBss : public NetlinkNestedAttribute { static bool ParseInformationElements(AttributeList* attribute_list, size_t id, const std::string& attribute_name, - ByteString data); + const ByteString& data); DISALLOW_COPY_AND_ASSIGN(Nl80211AttributeBss); }; diff --git a/net/rtnl_message_unittest.cc b/net/rtnl_message_unittest.cc index 3e74d93c..9824526f 100644 --- a/net/rtnl_message_unittest.cc +++ b/net/rtnl_message_unittest.cc @@ -389,10 +389,10 @@ class RTNLMessageTest : public Test { int interface_index, unsigned int flags, unsigned int change, - ByteString address, - ByteString name, + const ByteString& address, + const ByteString& name, uint32_t mtu, - ByteString qdisc, + const ByteString& qdisc, int oper_state) { RTNLMessage msg; EXPECT_TRUE(msg.Decode(packet)); diff --git a/scope_logger.cc b/scope_logger.cc index 815503f4..a5b515bf 100644 --- a/scope_logger.cc +++ b/scope_logger.cc @@ -154,7 +154,7 @@ void ScopeLogger::EnableScopesByName(const string& expression) { } void ScopeLogger::RegisterScopeEnableChangedCallback( - Scope scope, ScopeEnableChangedCallback callback) { + Scope scope, const ScopeEnableChangedCallback& callback) { CHECK_GE(scope, 0); CHECK_LT(scope, kNumScopes); log_scope_callbacks_[scope].push_back(callback); diff --git a/scope_logger.h b/scope_logger.h index 3d5a817b..44320975 100644 --- a/scope_logger.h +++ b/scope_logger.h @@ -116,7 +116,7 @@ class ScopeLogger { // Register for log scope enable/disable state changes for |scope|. void RegisterScopeEnableChangedCallback( - Scope scope, ScopeEnableChangedCallback callback); + Scope scope, const ScopeEnableChangedCallback& callback); // Sets the verbose level for all scopes to |verbose_level|. void set_verbose_level(int verbose_level) { verbose_level_ = verbose_level; } @@ -656,7 +656,7 @@ bool Service::Save(StoreInterface* storage) { } void Service::Configure(const KeyValueStore& args, Error* error) { - for (const auto it : args.properties()) { + for (const auto& it : args.properties()) { if (it.second.IsTypeCompatible<bool>()) { if (ContainsKey(parameters_ignored_for_configure_, it.first)) { SLOG(this, 5) << "Ignoring bool property: " << it.first; @@ -1061,8 +1061,8 @@ uint16_t Service::SecurityLevel() { // static bool Service::Compare(Manager* manager, - ServiceRefPtr a, - ServiceRefPtr b, + const ServiceRefPtr& a, + const ServiceRefPtr& b, bool compare_connectivity_state, const vector<Technology::Identifier>& tech_order, const char** reason) { @@ -448,8 +448,8 @@ class Service : public base::RefCounted<Service> { // difference. |reason| is populated with the exact criteria used for the // ultimate comparison. static bool Compare(Manager* manager, - ServiceRefPtr a, - ServiceRefPtr b, + const ServiceRefPtr& a, + const ServiceRefPtr& b, bool compare_connectivity_state, const std::vector<Technology::Identifier>& tech_order, const char** reason); @@ -686,9 +686,9 @@ class Service : public base::RefCounted<Service> { friend class WiFiServiceTest; friend class WiMaxProviderTest; friend class WiMaxServiceTest; - friend void TestCommonPropertyChanges(ServiceRefPtr, ServiceMockAdaptor*); - friend void TestCustomSetterNoopChange(ServiceRefPtr, MockManager*); - friend void TestNamePropertyChange(ServiceRefPtr, ServiceMockAdaptor*); + friend void TestCommonPropertyChanges(const ServiceRefPtr&, ServiceMockAdaptor*); + friend void TestCustomSetterNoopChange(const ServiceRefPtr&, MockManager*); + friend void TestNamePropertyChange(const ServiceRefPtr&, ServiceMockAdaptor*); FRIEND_TEST(AllMockServiceTest, AutoConnectWithFailures); FRIEND_TEST(CellularCapabilityGSMTest, SetStorageIdentifier); FRIEND_TEST(CellularServiceTest, IsAutoConnectable); diff --git a/service_property_change_notifier.cc b/service_property_change_notifier.cc index 97888c1c..2e9d704f 100644 --- a/service_property_change_notifier.cc +++ b/service_property_change_notifier.cc @@ -34,7 +34,7 @@ ServicePropertyChangeNotifier::ServicePropertyChangeNotifier( ServicePropertyChangeNotifier::~ServicePropertyChangeNotifier() {} void ServicePropertyChangeNotifier::AddBoolPropertyObserver( - const string& name, BoolAccessor accessor) { + const string& name, const BoolAccessor& accessor) { property_observers_.emplace_back( new PropertyObserver<bool>( accessor, @@ -44,7 +44,7 @@ void ServicePropertyChangeNotifier::AddBoolPropertyObserver( } void ServicePropertyChangeNotifier::AddUint8PropertyObserver( - const string& name, Uint8Accessor accessor) { + const string& name, const Uint8Accessor& accessor) { property_observers_.emplace_back( new PropertyObserver<uint8_t>( accessor, @@ -54,7 +54,7 @@ void ServicePropertyChangeNotifier::AddUint8PropertyObserver( } void ServicePropertyChangeNotifier::AddUint16PropertyObserver( - const string& name, Uint16Accessor accessor) { + const string& name, const Uint16Accessor& accessor) { property_observers_.emplace_back( new PropertyObserver<uint16_t>( accessor, @@ -64,7 +64,7 @@ void ServicePropertyChangeNotifier::AddUint16PropertyObserver( } void ServicePropertyChangeNotifier::AddUint16sPropertyObserver( - const string& name, Uint16sAccessor accessor) { + const string& name, const Uint16sAccessor& accessor) { property_observers_.emplace_back( new PropertyObserver<Uint16s>( accessor, @@ -74,7 +74,7 @@ void ServicePropertyChangeNotifier::AddUint16sPropertyObserver( } void ServicePropertyChangeNotifier::AddUintPropertyObserver( - const string& name, Uint32Accessor accessor) { + const string& name, const Uint32Accessor& accessor) { property_observers_.emplace_back( new PropertyObserver<uint32_t>( accessor, @@ -84,7 +84,7 @@ void ServicePropertyChangeNotifier::AddUintPropertyObserver( } void ServicePropertyChangeNotifier::AddIntPropertyObserver( - const string& name, Int32Accessor accessor) { + const string& name, const Int32Accessor& accessor) { property_observers_.emplace_back( new PropertyObserver<int32_t>( accessor, @@ -94,7 +94,7 @@ void ServicePropertyChangeNotifier::AddIntPropertyObserver( } void ServicePropertyChangeNotifier::AddRpcIdentifierPropertyObserver( - const string& name, RpcIdentifierAccessor accessor) { + const string& name, const RpcIdentifierAccessor& accessor) { property_observers_.emplace_back( new PropertyObserver<string>( accessor, @@ -104,7 +104,7 @@ void ServicePropertyChangeNotifier::AddRpcIdentifierPropertyObserver( } void ServicePropertyChangeNotifier::AddStringPropertyObserver( - const string& name, StringAccessor accessor) { + const string& name, const StringAccessor& accessor) { property_observers_.emplace_back( new PropertyObserver<string>( accessor, @@ -114,7 +114,7 @@ void ServicePropertyChangeNotifier::AddStringPropertyObserver( } void ServicePropertyChangeNotifier::AddStringmapPropertyObserver( - const string& name, StringmapAccessor accessor) { + const string& name, const StringmapAccessor& accessor) { property_observers_.emplace_back( new PropertyObserver<Stringmap>( accessor, diff --git a/service_property_change_notifier.h b/service_property_change_notifier.h index d60ee5e2..ff7814d9 100644 --- a/service_property_change_notifier.h +++ b/service_property_change_notifier.h @@ -42,23 +42,23 @@ class ServicePropertyChangeNotifier { virtual ~ServicePropertyChangeNotifier(); virtual void AddBoolPropertyObserver(const std::string& name, - BoolAccessor accessor); + const BoolAccessor& accessor); virtual void AddUint8PropertyObserver(const std::string& name, - Uint8Accessor accessor); + const Uint8Accessor& accessor); virtual void AddUint16PropertyObserver(const std::string& name, - Uint16Accessor accessor); + const Uint16Accessor& accessor); virtual void AddUint16sPropertyObserver(const std::string& name, - Uint16sAccessor accessor); + const Uint16sAccessor& accessor); virtual void AddUintPropertyObserver(const std::string& name, - Uint32Accessor accessor); + const Uint32Accessor& accessor); virtual void AddIntPropertyObserver(const std::string& name, - Int32Accessor accessor); + const Int32Accessor& accessor); virtual void AddRpcIdentifierPropertyObserver(const std::string& name, - RpcIdentifierAccessor accessor); + const RpcIdentifierAccessor& accessor); virtual void AddStringPropertyObserver(const std::string& name, - StringAccessor accessor); + const StringAccessor& accessor); virtual void AddStringmapPropertyObserver(const std::string& name, - StringmapAccessor accessor); + const StringmapAccessor& accessor); virtual void UpdatePropertyObservers(); private: diff --git a/service_property_change_test.cc b/service_property_change_test.cc index 4f214ffd..22abae40 100644 --- a/service_property_change_test.cc +++ b/service_property_change_test.cc @@ -45,7 +45,7 @@ namespace shill { // for specific setters. However, it's convenient to have all the property // change notifications documented (and tested) in one place. -void TestCommonPropertyChanges(ServiceRefPtr service, +void TestCommonPropertyChanges(const ServiceRefPtr& service, ServiceMockAdaptor* adaptor) { Error error; @@ -119,7 +119,7 @@ void TestCommonPropertyChanges(ServiceRefPtr service, Mock::VerifyAndClearExpectations(adaptor); } -void TestAutoConnectPropertyChange(ServiceRefPtr service, +void TestAutoConnectPropertyChange(const ServiceRefPtr& service, ServiceMockAdaptor* adaptor) { bool auto_connect = service->auto_connect(); EXPECT_CALL(*adaptor, EmitBoolChanged(kAutoConnectProperty, _)); @@ -127,7 +127,7 @@ void TestAutoConnectPropertyChange(ServiceRefPtr service, Mock::VerifyAndClearExpectations(adaptor); } -void TestNamePropertyChange(ServiceRefPtr service, +void TestNamePropertyChange(const ServiceRefPtr& service, ServiceMockAdaptor* adaptor) { Error error; string name = service->GetNameProperty(&error); @@ -136,7 +136,7 @@ void TestNamePropertyChange(ServiceRefPtr service, Mock::VerifyAndClearExpectations(adaptor); } -void TestCustomSetterNoopChange(ServiceRefPtr service, +void TestCustomSetterNoopChange(const ServiceRefPtr& service, MockManager* mock_manager) { // SetAutoConnectFull { diff --git a/service_property_change_test.h b/service_property_change_test.h index a49aa5c3..adb56581 100644 --- a/service_property_change_test.h +++ b/service_property_change_test.h @@ -26,15 +26,15 @@ class ServiceMockAdaptor; // Test property change notifications that are implemented by all // Services. -void TestCommonPropertyChanges(ServiceRefPtr service, +void TestCommonPropertyChanges(const ServiceRefPtr& service, ServiceMockAdaptor* adaptor); // Test AutoConnect property change notification. Implemented by // all Services except EthernetService. -void TestAutoConnectPropertyChange(ServiceRefPtr service, +void TestAutoConnectPropertyChange(const ServiceRefPtr& service, ServiceMockAdaptor* adaptor); // Test Name property change notification. Only VPNService allows // changing the name property. -void TestNamePropertyChange(ServiceRefPtr service, +void TestNamePropertyChange(const ServiceRefPtr& service, ServiceMockAdaptor* adaptor); // Test that the common customer setters (for all Services) return // false if setting to the same as the current value. diff --git a/service_sorter.h b/service_sorter.h index eb56b998..d9a92379 100644 --- a/service_sorter.h +++ b/service_sorter.h @@ -38,7 +38,7 @@ class ServiceSorter { : manager_(manager), compare_connectivity_state_(compare_connectivity_state), technology_order_(tech_order) {} - bool operator() (ServiceRefPtr a, ServiceRefPtr b) { + bool operator() (const ServiceRefPtr& a, const ServiceRefPtr& b) { const char* reason; return Service::Compare(manager_, a, b, compare_connectivity_state_, technology_order_, &reason); diff --git a/socket_info_unittest.cc b/socket_info_unittest.cc index e9f53f75..65947622 100644 --- a/socket_info_unittest.cc +++ b/socket_info_unittest.cc @@ -57,7 +57,7 @@ TEST_F(SocketInfoTest, CopyConstructor) { 20, SocketInfo::kTimerStateRetransmitTimerPending); - SocketInfo info_copy(info); + const SocketInfo& info_copy(info); ExpectSocketInfoEqual(info, info_copy); } @@ -73,7 +73,7 @@ TEST_F(SocketInfoTest, AssignmentOperator) { 20, SocketInfo::kTimerStateRetransmitTimerPending); - SocketInfo info_copy = info; + const SocketInfo& info_copy = info; ExpectSocketInfoEqual(info, info_copy); } diff --git a/test-rpc-proxy/proxy_rpc_in_data_types.cc b/test-rpc-proxy/proxy_rpc_in_data_types.cc index 1e24f5d2..b9746d02 100644 --- a/test-rpc-proxy/proxy_rpc_in_data_types.cc +++ b/test-rpc-proxy/proxy_rpc_in_data_types.cc @@ -23,7 +23,7 @@ static const char kXmlRpcStructTypeKey[] = "xmlrpc_struct_type_key"; void AssertStructTypeStringFromXmlRpcValue( XmlRpc::XmlRpcValue* xml_rpc_value_in, - std::string expected_type) { + const std::string& expected_type) { if ((*xml_rpc_value_in)[kXmlRpcStructTypeKey] != expected_type) { LOG(FATAL) << "Unexpected object received. Expected: " << expected_type << "Recieved: " << (*xml_rpc_value_in)[kXmlRpcStructTypeKey]; diff --git a/vpn/vpn_provider.cc b/vpn/vpn_provider.cc index b9965b61..163037c8 100644 --- a/vpn/vpn_provider.cc +++ b/vpn/vpn_provider.cc @@ -181,7 +181,7 @@ bool VPNProvider::OnDeviceInfoAvailable(const string& link_name, return false; } -void VPNProvider::RemoveService(VPNServiceRefPtr service) { +void VPNProvider::RemoveService(const VPNServiceRefPtr& service) { const auto it = std::find(services_.begin(), services_.end(), service); if (it != services_.end()) { services_.erase(it); diff --git a/vpn/vpn_provider.h b/vpn/vpn_provider.h index 08c8923f..3bd2d907 100644 --- a/vpn/vpn_provider.h +++ b/vpn/vpn_provider.h @@ -68,7 +68,7 @@ class VPNProvider : public ProviderInterface { // Clean up a VPN services that has been unloaded and will be deregistered. // This removes the VPN provider's reference to this service in its // services_ vector. - void RemoveService(VPNServiceRefPtr service); + void RemoveService(const VPNServiceRefPtr& service); // Returns true if any of the managed VPN services is connecting or connected. virtual bool HasActiveService() const; |