From f05cc26630828c848e46ea0e584dbdd2541ea723 Mon Sep 17 00:00:00 2001 From: Chih-Hung Hsieh Date: Wed, 27 Jul 2016 11:42:51 -0700 Subject: Fix clang-tidy performance warnings. * 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: Ia09c58becfa3980faed24aa7eddeb520207ca259 Test: build with WITH_TIDY=1 --- aidl.cpp | 6 +++--- aidl.h | 4 ++-- aidl_language.cpp | 2 +- aidl_language.h | 2 +- generate_cpp.cpp | 8 ++++---- tests/aidl_test_client_file_descriptors.cpp | 4 ++-- tests/aidl_test_client_nullables.cpp | 2 +- type_cpp.h | 2 +- type_namespace.h | 2 +- 9 files changed, 16 insertions(+), 16 deletions(-) diff --git a/aidl.cpp b/aidl.cpp index 513aaee..cd778fa 100644 --- a/aidl.cpp +++ b/aidl.cpp @@ -330,7 +330,7 @@ bool write_cpp_dep_file(const CppOptions& options, string generate_outputFileName(const JavaOptions& options, const AidlInterface& interface) { - string name = interface.GetName(); + const string& name = interface.GetName(); string package = interface.GetPackage(); string result; @@ -536,8 +536,8 @@ bool parse_preprocessed_file(const IoDelegate& io_delegate, } AidlError load_and_validate_aidl( - const std::vector preprocessed_files, - const std::vector import_paths, + const std::vector& preprocessed_files, + const std::vector& import_paths, const std::string& input_file_name, const IoDelegate& io_delegate, TypeNamespace* types, diff --git a/aidl.h b/aidl.h index dffdf14..2e5b0ee 100644 --- a/aidl.h +++ b/aidl.h @@ -55,8 +55,8 @@ bool preprocess_aidl(const JavaOptions& options, namespace internals { AidlError load_and_validate_aidl( - const std::vector preprocessed_files, - const std::vector import_paths, + const std::vector& preprocessed_files, + const std::vector& import_paths, const std::string& input_file_name, const IoDelegate& io_delegate, TypeNamespace* types, diff --git a/aidl_language.cpp b/aidl_language.cpp index 608c9f6..6af55f8 100644 --- a/aidl_language.cpp +++ b/aidl_language.cpp @@ -244,7 +244,7 @@ AidlQualifiedName::AidlQualifiedName(std::string term, } } -void AidlQualifiedName::AddTerm(std::string term) { +void AidlQualifiedName::AddTerm(const std::string& term) { terms_.push_back(term); } diff --git a/aidl_language.h b/aidl_language.h index 43b8a9d..e27cd10 100644 --- a/aidl_language.h +++ b/aidl_language.h @@ -279,7 +279,7 @@ class AidlQualifiedName : public AidlNode { const std::string& GetComments() const { return comments_; } std::string GetDotName() const { return android::base::Join(terms_, '.'); } - void AddTerm(std::string term); + void AddTerm(const std::string& term); private: std::vector terms_; diff --git a/generate_cpp.cpp b/generate_cpp.cpp index 77badc4..a8b2157 100644 --- a/generate_cpp.cpp +++ b/generate_cpp.cpp @@ -284,7 +284,7 @@ unique_ptr DefineClientTransaction(const TypeNamespace& types, // if (_aidl_ret_status != ::android::OK) { goto error; } for (const AidlArgument* a : method.GetInArguments()) { const Type* type = a->GetType().GetLanguageType(); - string method = type->WriteToParcelMethod(); + const string& method = type->WriteToParcelMethod(); string var_name = ((a->IsOut()) ? "*" : "") + a->GetName(); var_name = type->WriteCast(var_name); @@ -334,7 +334,7 @@ unique_ptr DefineClientTransaction(const TypeNamespace& types, // If the method is expected to return something, read it first by convention. const Type* return_type = method.GetType().GetLanguageType(); if (return_type != types.VoidType()) { - string method_call = return_type->ReadFromParcelMethod(); + const string& method_call = return_type->ReadFromParcelMethod(); b->AddStatement(new Assignment( kAndroidStatusVarName, new MethodCall(StringPrintf("%s.%s", kReplyVarName, @@ -438,7 +438,7 @@ bool HandleServerTransaction(const TypeNamespace& types, // _aidl_ret_status = _aidl_data.ReadInt32(&in_param_name); // if (_aidl_ret_status != ::android::OK) { break; } const Type* type = a->GetType().GetLanguageType(); - string readMethod = type->ReadFromParcelMethod(); + const string& readMethod = type->ReadFromParcelMethod(); b->AddStatement(new Assignment{ kAndroidStatusVarName, @@ -485,7 +485,7 @@ bool HandleServerTransaction(const TypeNamespace& types, // _aidl_ret_status = data.WriteInt32(out_param_name); // if (_aidl_ret_status != ::android::OK) { break; } const Type* type = a->GetType().GetLanguageType(); - string writeMethod = type->WriteToParcelMethod(); + const string& writeMethod = type->WriteToParcelMethod(); b->AddStatement(new Assignment{ kAndroidStatusVarName, diff --git a/tests/aidl_test_client_file_descriptors.cpp b/tests/aidl_test_client_file_descriptors.cpp index afe1f54..b5913a3 100644 --- a/tests/aidl_test_client_file_descriptors.cpp +++ b/tests/aidl_test_client_file_descriptors.cpp @@ -50,7 +50,7 @@ namespace client { #define FdByName(_fd) #_fd, _fd -bool DoWrite(string name, const unique_fd& fd, const string& buf) { +bool DoWrite(const string& name, const unique_fd& fd, const string& buf) { int wrote; while ((wrote = write(fd.get(), buf.data(), buf.size())) < 0 && errno == EINTR); @@ -69,7 +69,7 @@ bool DoWrite(string name, const unique_fd& fd, const string& buf) { return false; } -bool DoRead(string name, const unique_fd& fd, const string& expected) { +bool DoRead(const string& name, const unique_fd& fd, const string& expected) { size_t length = expected.size(); int got; string buf; diff --git a/tests/aidl_test_client_nullables.cpp b/tests/aidl_test_client_nullables.cpp index e876af4..805827c 100644 --- a/tests/aidl_test_client_nullables.cpp +++ b/tests/aidl_test_client_nullables.cpp @@ -89,7 +89,7 @@ bool ValuesEqual>>( } template -bool ConfirmNullableType(const sp& s, string type_name, +bool ConfirmNullableType(const sp& s, const string& type_name, unique_ptr in, Status(ITestService::*func)(const unique_ptr&, unique_ptr*)) { diff --git a/type_cpp.h b/type_cpp.h index 66b2ed5..1130839 100644 --- a/type_cpp.h +++ b/type_cpp.h @@ -60,7 +60,7 @@ class Type : public ValidatableType { } void GetHeaders(std::set* headers) const { - for (std::string header : headers_) { + for (const std::string& header : headers_) { if (!header.empty()) { headers->insert(header); } diff --git a/type_namespace.h b/type_namespace.h index caea1fa..7defd24 100644 --- a/type_namespace.h +++ b/type_namespace.h @@ -272,7 +272,7 @@ bool LanguageTypeNamespace::MaybeAddContainerType( const AidlType& aidl_type) { using android::base::Join; - std::string type_name = aidl_type.GetName(); + const std::string& type_name = aidl_type.GetName(); if (!IsContainerType(type_name)) { return true; } -- cgit v1.2.3