From e8b3bac597cffec781a5f239f99f1b848bad6861 Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Mon, 9 Mar 2020 00:53:03 +0300 Subject: [PATCH] clang-tidy, part 5 --- .../performance-test/ConfigPreprocessor.cpp | 2 +- dbms/src/Access/AccessControlManager.cpp | 4 +-- dbms/src/Access/AccessRights.h | 32 +++++++++---------- dbms/src/Access/AccessRightsContext.h | 4 +-- dbms/src/Access/DiskAccessStorage.cpp | 2 +- dbms/src/Access/GenericRoleSet.cpp | 10 ++---- dbms/src/Access/MemoryAccessStorage.cpp | 3 -- dbms/src/Access/MemoryAccessStorage.h | 1 - dbms/src/Access/MultipleAccessStorage.cpp | 5 --- dbms/src/Access/MultipleAccessStorage.h | 1 - dbms/src/Access/QuotaContextFactory.cpp | 4 +-- dbms/src/Access/RowPolicyContextFactory.cpp | 2 +- dbms/src/Access/UsersConfigAccessStorage.cpp | 3 -- dbms/src/Access/UsersConfigAccessStorage.h | 1 - .../getDictionaryConfigurationFromAST.cpp | 4 +-- dbms/src/Interpreters/ExpressionActions.cpp | 2 +- dbms/src/Parsers/ASTDictionary.cpp | 4 +-- dbms/src/Parsers/ASTIdentifier.cpp | 4 +-- .../Formats/Impl/AvroRowOutputFormat.cpp | 2 +- .../Storages/MergeTree/MergeTreeIndices.cpp | 9 +++--- 20 files changed, 38 insertions(+), 61 deletions(-) diff --git a/dbms/programs/performance-test/ConfigPreprocessor.cpp b/dbms/programs/performance-test/ConfigPreprocessor.cpp index 8dabac0ec3..850fd9f14c 100644 --- a/dbms/programs/performance-test/ConfigPreprocessor.cpp +++ b/dbms/programs/performance-test/ConfigPreprocessor.cpp @@ -21,7 +21,7 @@ std::vector ConfigPreprocessor::processConfig( const auto path = Poco::Path(path_str); test->setString("path", path.absolute().toString()); - if (test->getString("name", "") == "") + if (test->getString("name", "").empty()) test->setString("name", path.getBaseName()); } diff --git a/dbms/src/Access/AccessControlManager.cpp b/dbms/src/Access/AccessControlManager.cpp index 3261e30ec5..b3854e69ee 100644 --- a/dbms/src/Access/AccessControlManager.cpp +++ b/dbms/src/Access/AccessControlManager.cpp @@ -37,9 +37,7 @@ AccessControlManager::AccessControlManager() } -AccessControlManager::~AccessControlManager() -{ -} +AccessControlManager::~AccessControlManager() = default; void AccessControlManager::setLocalDirectory(const String & directory_path) diff --git a/dbms/src/Access/AccessRights.h b/dbms/src/Access/AccessRights.h index 5c5ed382f5..67d205ec6d 100644 --- a/dbms/src/Access/AccessRights.h +++ b/dbms/src/Access/AccessRights.h @@ -34,8 +34,8 @@ public: void grant(const AccessFlags & access, const std::string_view & database, const std::string_view & table, const std::string_view & column); void grant(const AccessFlags & access, const std::string_view & database, const std::string_view & table, const std::vector & columns); void grant(const AccessFlags & access, const std::string_view & database, const std::string_view & table, const Strings & columns); - void grant(const AccessRightsElement & access, std::string_view current_database = {}); - void grant(const AccessRightsElements & access, std::string_view current_database = {}); + void grant(const AccessRightsElement & element, std::string_view current_database = {}); + void grant(const AccessRightsElements & elements, std::string_view current_database = {}); /// Revokes a specified access granted earlier on a specified database/table/column. /// Does nothing if the specified access is not granted. @@ -48,8 +48,8 @@ public: void revoke(const AccessFlags & access, const std::string_view & database, const std::string_view & table, const std::string_view & column); void revoke(const AccessFlags & access, const std::string_view & database, const std::string_view & table, const std::vector & columns); void revoke(const AccessFlags & access, const std::string_view & database, const std::string_view & table, const Strings & columns); - void revoke(const AccessRightsElement & access, std::string_view current_database = {}); - void revoke(const AccessRightsElements & access, std::string_view current_database = {}); + void revoke(const AccessRightsElement & element, std::string_view current_database = {}); + void revoke(const AccessRightsElements & elements, std::string_view current_database = {}); /// Revokes a specified access granted earlier on a specified database/table/column or on lower levels. /// The function also restricts access if it's granted on upper level. @@ -61,8 +61,8 @@ public: void partialRevoke(const AccessFlags & access, const std::string_view & database, const std::string_view & table, const std::string_view & column); void partialRevoke(const AccessFlags & access, const std::string_view & database, const std::string_view & table, const std::vector & columns); void partialRevoke(const AccessFlags & access, const std::string_view & database, const std::string_view & table, const Strings & columns); - void partialRevoke(const AccessRightsElement & access, std::string_view current_database = {}); - void partialRevoke(const AccessRightsElements & access, std::string_view current_database = {}); + void partialRevoke(const AccessRightsElement & element, std::string_view current_database = {}); + void partialRevoke(const AccessRightsElements & elements, std::string_view current_database = {}); /// Revokes a specified access granted earlier on a specified database/table/column or on lower levels. /// The function also restricts access if it's granted on upper level. @@ -74,8 +74,8 @@ public: void fullRevoke(const AccessFlags & access, const std::string_view & database, const std::string_view & table, const std::string_view & column); void fullRevoke(const AccessFlags & access, const std::string_view & database, const std::string_view & table, const std::vector & columns); void fullRevoke(const AccessFlags & access, const std::string_view & database, const std::string_view & table, const Strings & columns); - void fullRevoke(const AccessRightsElement & access, std::string_view current_database = {}); - void fullRevoke(const AccessRightsElements & access, std::string_view current_database = {}); + void fullRevoke(const AccessRightsElement & element, std::string_view current_database = {}); + void fullRevoke(const AccessRightsElements & elements, std::string_view current_database = {}); /// Returns the information about all the access granted. struct Elements @@ -95,8 +95,8 @@ public: bool isGranted(const AccessFlags & access, const std::string_view & database, const std::string_view & table, const std::string_view & column) const; bool isGranted(const AccessFlags & access, const std::string_view & database, const std::string_view & table, const std::vector & columns) const; bool isGranted(const AccessFlags & access, const std::string_view & database, const std::string_view & table, const Strings & columns) const; - bool isGranted(const AccessRightsElement & access, std::string_view current_database = {}) const; - bool isGranted(const AccessRightsElements & access, std::string_view current_database = {}) const; + bool isGranted(const AccessRightsElement & element, std::string_view current_database = {}) const; + bool isGranted(const AccessRightsElements & elements, std::string_view current_database = {}) const; friend bool operator ==(const AccessRights & left, const AccessRights & right); friend bool operator !=(const AccessRights & left, const AccessRights & right) { return !(left == right); } @@ -109,23 +109,23 @@ private: template void grantImpl(const AccessFlags & access, const Args &... args); - void grantImpl(const AccessRightsElement & access, std::string_view current_database); - void grantImpl(const AccessRightsElements & access, std::string_view current_database); + void grantImpl(const AccessRightsElement & element, std::string_view current_database); + void grantImpl(const AccessRightsElements & elements, std::string_view current_database); template void revokeImpl(const AccessFlags & access, const Args &... args); template - void revokeImpl(const AccessRightsElement & access, std::string_view current_database); + void revokeImpl(const AccessRightsElement & element, std::string_view current_database); template - void revokeImpl(const AccessRightsElements & access, std::string_view current_database); + void revokeImpl(const AccessRightsElements & elements, std::string_view current_database); template bool isGrantedImpl(const AccessFlags & access, const Args &... args) const; - bool isGrantedImpl(const AccessRightsElement & access, std::string_view current_database) const; - bool isGrantedImpl(const AccessRightsElements & access, std::string_view current_database) const; + bool isGrantedImpl(const AccessRightsElement & element, std::string_view current_database) const; + bool isGrantedImpl(const AccessRightsElements & elements, std::string_view current_database) const; template AccessFlags getAccessImpl(const Args &... args) const; diff --git a/dbms/src/Access/AccessRightsContext.h b/dbms/src/Access/AccessRightsContext.h index be6101e5e9..8fc5066cfe 100644 --- a/dbms/src/Access/AccessRightsContext.h +++ b/dbms/src/Access/AccessRightsContext.h @@ -128,10 +128,10 @@ private: bool checkAccessImpl(Poco::Logger * log_, const AccessFlags & access, const Args &... args) const; template - bool checkAccessImpl(Poco::Logger * log_, const AccessRightsElement & access) const; + bool checkAccessImpl(Poco::Logger * log_, const AccessRightsElement & element) const; template - bool checkAccessImpl(Poco::Logger * log_, const AccessRightsElements & access) const; + bool checkAccessImpl(Poco::Logger * log_, const AccessRightsElements & elements) const; boost::shared_ptr calculateResultAccess(bool grant_option) const; boost::shared_ptr calculateResultAccess(bool grant_option, UInt64 readonly_, bool allow_ddl_, bool allow_introspection_) const; diff --git a/dbms/src/Access/DiskAccessStorage.cpp b/dbms/src/Access/DiskAccessStorage.cpp index 1707526b50..f5f42e1ff8 100644 --- a/dbms/src/Access/DiskAccessStorage.cpp +++ b/dbms/src/Access/DiskAccessStorage.cpp @@ -254,7 +254,7 @@ namespace } - static const std::vector & getAllAccessEntityTypes() + const std::vector & getAllAccessEntityTypes() { static const std::vector res = {typeid(User), typeid(Role), typeid(RowPolicy), typeid(Quota)}; return res; diff --git a/dbms/src/Access/GenericRoleSet.cpp b/dbms/src/Access/GenericRoleSet.cpp index 89029c8933..1e751f995c 100644 --- a/dbms/src/Access/GenericRoleSet.cpp +++ b/dbms/src/Access/GenericRoleSet.cpp @@ -270,10 +270,7 @@ bool GenericRoleSet::match(const UUID & user_id, const std::vector & enabl bool in_except_list = std::any_of( enabled_roles.begin(), enabled_roles.end(), [this](const UUID & enabled_role) { return except_ids.contains(enabled_role); }); - if (in_except_list) - return false; - - return true; + return !in_except_list; } @@ -292,10 +289,7 @@ bool GenericRoleSet::match(const UUID & user_id, const boost::container::flat_se bool in_except_list = std::any_of( enabled_roles.begin(), enabled_roles.end(), [this](const UUID & enabled_role) { return except_ids.contains(enabled_role); }); - if (in_except_list) - return false; - - return true; + return !in_except_list; } diff --git a/dbms/src/Access/MemoryAccessStorage.cpp b/dbms/src/Access/MemoryAccessStorage.cpp index 51614c587e..ce668bcd8b 100644 --- a/dbms/src/Access/MemoryAccessStorage.cpp +++ b/dbms/src/Access/MemoryAccessStorage.cpp @@ -11,9 +11,6 @@ MemoryAccessStorage::MemoryAccessStorage(const String & storage_name_) } -MemoryAccessStorage::~MemoryAccessStorage() {} - - std::optional MemoryAccessStorage::findImpl(std::type_index type, const String & name) const { std::lock_guard lock{mutex}; diff --git a/dbms/src/Access/MemoryAccessStorage.h b/dbms/src/Access/MemoryAccessStorage.h index e060e953b1..b93c2868d3 100644 --- a/dbms/src/Access/MemoryAccessStorage.h +++ b/dbms/src/Access/MemoryAccessStorage.h @@ -14,7 +14,6 @@ class MemoryAccessStorage : public IAccessStorage { public: MemoryAccessStorage(const String & storage_name_ = "memory"); - ~MemoryAccessStorage() override; /// Sets all entities at once. void setAll(const std::vector & all_entities); diff --git a/dbms/src/Access/MultipleAccessStorage.cpp b/dbms/src/Access/MultipleAccessStorage.cpp index 316df11fad..3474ab9dbd 100644 --- a/dbms/src/Access/MultipleAccessStorage.cpp +++ b/dbms/src/Access/MultipleAccessStorage.cpp @@ -38,11 +38,6 @@ MultipleAccessStorage::MultipleAccessStorage( } -MultipleAccessStorage::~MultipleAccessStorage() -{ -} - - std::vector MultipleAccessStorage::findMultiple(std::type_index type, const String & name) const { std::vector ids; diff --git a/dbms/src/Access/MultipleAccessStorage.h b/dbms/src/Access/MultipleAccessStorage.h index bdbb6988c8..898d55d30d 100644 --- a/dbms/src/Access/MultipleAccessStorage.h +++ b/dbms/src/Access/MultipleAccessStorage.h @@ -14,7 +14,6 @@ public: using Storage = IAccessStorage; MultipleAccessStorage(std::vector> nested_storages_); - ~MultipleAccessStorage() override; std::vector findMultiple(std::type_index type, const String & name) const; diff --git a/dbms/src/Access/QuotaContextFactory.cpp b/dbms/src/Access/QuotaContextFactory.cpp index f986ee86c0..7c585bddde 100644 --- a/dbms/src/Access/QuotaContextFactory.cpp +++ b/dbms/src/Access/QuotaContextFactory.cpp @@ -170,9 +170,7 @@ QuotaContextFactory::QuotaContextFactory(const AccessControlManager & access_con } -QuotaContextFactory::~QuotaContextFactory() -{ -} +QuotaContextFactory::~QuotaContextFactory() = default; QuotaContextPtr QuotaContextFactory::createContext(const String & user_name, const UUID & user_id, const std::vector & enabled_roles, const Poco::Net::IPAddress & address, const String & client_key) diff --git a/dbms/src/Access/RowPolicyContextFactory.cpp b/dbms/src/Access/RowPolicyContextFactory.cpp index 49a23c4d61..e891f43b5e 100644 --- a/dbms/src/Access/RowPolicyContextFactory.cpp +++ b/dbms/src/Access/RowPolicyContextFactory.cpp @@ -93,7 +93,7 @@ namespace using ConditionIndex = RowPolicy::ConditionIndex; - static constexpr size_t MAX_CONDITION_INDEX = RowPolicy::MAX_CONDITION_INDEX; + constexpr size_t MAX_CONDITION_INDEX = RowPolicy::MAX_CONDITION_INDEX; /// Accumulates conditions from multiple row policies and joins them using the AND logical operation. diff --git a/dbms/src/Access/UsersConfigAccessStorage.cpp b/dbms/src/Access/UsersConfigAccessStorage.cpp index 72d4646822..20ee2a628a 100644 --- a/dbms/src/Access/UsersConfigAccessStorage.cpp +++ b/dbms/src/Access/UsersConfigAccessStorage.cpp @@ -339,9 +339,6 @@ UsersConfigAccessStorage::UsersConfigAccessStorage() : IAccessStorage("users.xml } -UsersConfigAccessStorage::~UsersConfigAccessStorage() {} - - void UsersConfigAccessStorage::setConfiguration(const Poco::Util::AbstractConfiguration & config) { std::vector> all_entities; diff --git a/dbms/src/Access/UsersConfigAccessStorage.h b/dbms/src/Access/UsersConfigAccessStorage.h index 672d8ee2ad..773d8caa57 100644 --- a/dbms/src/Access/UsersConfigAccessStorage.h +++ b/dbms/src/Access/UsersConfigAccessStorage.h @@ -19,7 +19,6 @@ class UsersConfigAccessStorage : public IAccessStorage { public: UsersConfigAccessStorage(); - ~UsersConfigAccessStorage() override; void setConfiguration(const Poco::Util::AbstractConfiguration & config); diff --git a/dbms/src/Dictionaries/getDictionaryConfigurationFromAST.cpp b/dbms/src/Dictionaries/getDictionaryConfigurationFromAST.cpp index dbbcc0e41a..a1d898b262 100644 --- a/dbms/src/Dictionaries/getDictionaryConfigurationFromAST.cpp +++ b/dbms/src/Dictionaries/getDictionaryConfigurationFromAST.cpp @@ -311,9 +311,9 @@ NamesToTypeNames buildDictionaryAttributesConfiguration( { const auto & children = dictionary_attributes->children; NamesToTypeNames attributes_names_and_types; - for (size_t i = 0; i < children.size(); ++i) + for (const auto & child : children) { - const ASTDictionaryAttributeDeclaration * dict_attr = children[i]->as(); + const ASTDictionaryAttributeDeclaration * dict_attr = child->as(); if (!dict_attr->type) throw Exception("Dictionary attribute must has type", ErrorCodes::INCORRECT_DICTIONARY_DEFINITION); diff --git a/dbms/src/Interpreters/ExpressionActions.cpp b/dbms/src/Interpreters/ExpressionActions.cpp index edfc2a5b2b..dafb270def 100644 --- a/dbms/src/Interpreters/ExpressionActions.cpp +++ b/dbms/src/Interpreters/ExpressionActions.cpp @@ -64,7 +64,7 @@ ExpressionAction ExpressionAction::applyFunction( const std::vector & argument_names_, std::string result_name_) { - if (result_name_ == "") + if (result_name_.empty()) { result_name_ = function_->getName() + "("; for (size_t i = 0 ; i < argument_names_.size(); ++i) diff --git a/dbms/src/Parsers/ASTDictionary.cpp b/dbms/src/Parsers/ASTDictionary.cpp index 630764fddb..5c477c2aab 100644 --- a/dbms/src/Parsers/ASTDictionary.cpp +++ b/dbms/src/Parsers/ASTDictionary.cpp @@ -76,7 +76,7 @@ ASTPtr ASTDictionaryLayout::clone() const void ASTDictionaryLayout::formatImpl(const FormatSettings & settings, FormatState & state, - FormatStateStacked expected) const + FormatStateStacked frame) const { settings.ostr << (settings.hilite ? hilite_keyword : "") << "LAYOUT" @@ -94,7 +94,7 @@ void ASTDictionaryLayout::formatImpl(const FormatSettings & settings, << (settings.hilite ? hilite_none : "") << " "; - parameter->second->formatImpl(settings, state, expected); + parameter->second->formatImpl(settings, state, frame); } settings.ostr << ")"; settings.ostr << ")"; diff --git a/dbms/src/Parsers/ASTIdentifier.cpp b/dbms/src/Parsers/ASTIdentifier.cpp index 6307db675f..8d8ba93615 100644 --- a/dbms/src/Parsers/ASTIdentifier.cpp +++ b/dbms/src/Parsers/ASTIdentifier.cpp @@ -34,10 +34,10 @@ ASTIdentifier::ASTIdentifier(const String & name_, std::vector && name_p , name_parts(name_parts_) , semantic(std::make_shared()) { - if (name_parts.size() && name_parts[0] == "") + if (!name_parts.empty() && name_parts[0].empty()) name_parts.erase(name_parts.begin()); - if (name == "") + if (name.empty()) { if (name_parts.size() == 2) name = name_parts[0] + '.' + name_parts[1]; diff --git a/dbms/src/Processors/Formats/Impl/AvroRowOutputFormat.cpp b/dbms/src/Processors/Formats/Impl/AvroRowOutputFormat.cpp index 93e46032a6..65fac6d87f 100644 --- a/dbms/src/Processors/Formats/Impl/AvroRowOutputFormat.cpp +++ b/dbms/src/Processors/Formats/Impl/AvroRowOutputFormat.cpp @@ -315,7 +315,7 @@ void AvroSerializer::serializeRow(const Columns & columns, size_t row_num, avro: static avro::Codec getCodec(const std::string & codec_name) { - if (codec_name == "") + if (codec_name.empty()) { #ifdef SNAPPY_CODEC_AVAILABLE return avro::Codec::SNAPPY_CODEC; diff --git a/dbms/src/Storages/MergeTree/MergeTreeIndices.cpp b/dbms/src/Storages/MergeTree/MergeTreeIndices.cpp index 9fe475a00c..93046f6fe2 100644 --- a/dbms/src/Storages/MergeTree/MergeTreeIndices.cpp +++ b/dbms/src/Storages/MergeTree/MergeTreeIndices.cpp @@ -43,11 +43,12 @@ std::unique_ptr MergeTreeIndexFactory::get( throw Exception( "Unknown Index type '" + node->type->name + "'. Available index types: " + std::accumulate(indexes.cbegin(), indexes.cend(), std::string{}, - [] (auto && lft, const auto & rht) -> std::string { - if (lft == "") - return rht.first; + [] (auto && left, const auto & right) -> std::string + { + if (left.empty()) + return right.first; else - return lft + ", " + rht.first; + return left + ", " + right.first; }), ErrorCodes::INCORRECT_QUERY); -- GitLab