diff --git a/Source/.clang-tidy b/Source/.clang-tidy index 33e8a7e3e..01cb0c934 100644 --- a/Source/.clang-tidy +++ b/Source/.clang-tidy @@ -44,7 +44,10 @@ Checks: > performance-implicit-conversion-in-loop, performance-inefficient-algorithm, performance-inefficient-string-concatenation, - performance-inefficient-vector-operation + performance-inefficient-vector-operation, + performance-move-const-arg, + performance-move-constructor-init, + performance-no-automatic-move CheckOptions: - key: modernize-loop-convert.MinConfidence diff --git a/Source/Config/source/ConfigImpl.cpp b/Source/Config/source/ConfigImpl.cpp index 5654f2497..fd59536f7 100644 --- a/Source/Config/source/ConfigImpl.cpp +++ b/Source/Config/source/ConfigImpl.cpp @@ -349,7 +349,7 @@ void ConfigImpl::InsertObserver(std::string_view _path, base::intrusive_ptrobservers.emplace_back(std::move(_observer)); - m_Observers.emplace(std::move(path), std::move(new_observers)); + m_Observers.emplace(path, std::move(new_observers)); } } diff --git a/Source/NimbleCommander/NimbleCommander/States/FilePanels/Actions/BatchRename.mm b/Source/NimbleCommander/NimbleCommander/States/FilePanels/Actions/BatchRename.mm index c2472a37f..8af748522 100644 --- a/Source/NimbleCommander/NimbleCommander/States/FilePanels/Actions/BatchRename.mm +++ b/Source/NimbleCommander/NimbleCommander/States/FilePanels/Actions/BatchRename.mm @@ -34,7 +34,7 @@ if( !all_of(begin(items), end(items), [=](auto &i) { return i.Host() == host; }) ) return; // currently BatchRenameOperation supports only single host for items - const auto sheet = [[NCOpsBatchRenamingDialog alloc] initWithItems:std::move(items)]; + const auto sheet = [[NCOpsBatchRenamingDialog alloc] initWithItems:items]; sheet.renamePatternDataSource = [[SimpleComboBoxPersistentDataSource alloc] initWithStateConfigPath:g_ConfigPatternsPath]; sheet.searchForDataSource = diff --git a/Source/NimbleCommander/NimbleCommander/States/FilePanels/Actions/CopyFile.mm b/Source/NimbleCommander/NimbleCommander/States/FilePanels/Actions/CopyFile.mm index aaa9cf4db..3f8a33eeb 100644 --- a/Source/NimbleCommander/NimbleCommander/States/FilePanels/Actions/CopyFile.mm +++ b/Source/NimbleCommander/NimbleCommander/States/FilePanels/Actions/CopyFile.mm @@ -93,7 +93,7 @@ if( !host || path.empty() ) return; // ui invariant is broken - const auto op = std::make_shared(std::move(entries), path, host, opts); + const auto op = std::make_shared(entries, path, host, opts); const auto update_both_panels = RefreshBothCurrentControllersLambda(_target); op->ObserveUnticketed(nc::ops::Operation::NotifyAboutFinish, update_both_panels); @@ -237,7 +237,7 @@ if( !host || path.empty() ) return; // ui invariant is broken - const auto op = std::make_shared(std::move(entries), path, host, opts); + const auto op = std::make_shared(entries, path, host, opts); const auto update_both_panels = RefreshBothCurrentControllersLambda(_target); op->ObserveUnticketed(nc::ops::Operation::NotifyAboutFinish, update_both_panels); diff --git a/Source/NimbleCommander/NimbleCommander/States/FilePanels/DragReceiver.mm b/Source/NimbleCommander/NimbleCommander/States/FilePanels/DragReceiver.mm index 221256ac3..1990fa72d 100644 --- a/Source/NimbleCommander/NimbleCommander/States/FilePanels/DragReceiver.mm +++ b/Source/NimbleCommander/NimbleCommander/States/FilePanels/DragReceiver.mm @@ -289,16 +289,14 @@ const auto operation = BuildOperationForLocal(_source, _destination); if( operation == NSDragOperationCopy ) { const auto opts = MakeDefaultFileCopyOptions(); - const auto op = - std::make_shared(std::move(files), _destination.Path(), _destination.Host(), opts); + const auto op = std::make_shared(files, _destination.Path(), _destination.Host(), opts); AddPanelRefreshIfNecessary(m_Target, *op); [m_Target.mainWindowController enqueueOperation:op]; return true; } else if( operation == NSDragOperationMove ) { const auto opts = MakeDefaultFileMoveOptions(); - const auto op = - std::make_shared(std::move(files), _destination.Path(), _destination.Host(), opts); + const auto op = std::make_shared(files, _destination.Path(), _destination.Host(), opts); AddPanelRefreshIfNecessary(m_Target, _source.sourceController, *op); [m_Target.mainWindowController enqueueOperation:op]; return true; diff --git a/Source/NimbleCommander/NimbleCommander/States/FilePanels/FindFilesSheetController.mm b/Source/NimbleCommander/NimbleCommander/States/FilePanels/FindFilesSheetController.mm index bd4e5b728..d3f9df531 100644 --- a/Source/NimbleCommander/NimbleCommander/States/FilePanels/FindFilesSheetController.mm +++ b/Source/NimbleCommander/NimbleCommander/States/FilePanels/FindFilesSheetController.mm @@ -717,7 +717,7 @@ - (IBAction)onSearchSettingsUIChanged:(id) [[maybe_unused]] sender const auto search_fied_value = self.maskSearchField.stringValue; - const auto query = search_fied_value != nil ? std::string(search_fied_value.UTF8String) : std::string{}; + auto query = search_fied_value != nil ? std::string(search_fied_value.UTF8String) : std::string{}; if( query.empty() ) return {}; if( m_RegexSearch ) { diff --git a/Source/NimbleCommander/NimbleCommander/States/FilePanels/NCPanelOpenWithMenuDelegate.h b/Source/NimbleCommander/NimbleCommander/States/FilePanels/NCPanelOpenWithMenuDelegate.h index 508b35794..dbed437f8 100644 --- a/Source/NimbleCommander/NimbleCommander/States/FilePanels/NCPanelOpenWithMenuDelegate.h +++ b/Source/NimbleCommander/NimbleCommander/States/FilePanels/NCPanelOpenWithMenuDelegate.h @@ -1,4 +1,4 @@ -// Copyright (C) 2017-2019 Michael Kazakov. Subject to GNU General Public License version 3. +// Copyright (C) 2017-2024 Michael Kazakov. Subject to GNU General Public License version 3. #pragma once #include @@ -19,7 +19,7 @@ class FileOpener; - (instancetype)init NS_UNAVAILABLE; - (instancetype)initWithFileOpener:(nc::panel::FileOpener &)_file_opener utiDB:(const nc::utility::UTIDB &)_uti_db; -- (void)setContextSource:(const std::vector)_items; +- (void)setContextSource:(const std::vector&)_items; - (void)addManagedMenu:(NSMenu *)_menu; @property(weak, nonatomic) PanelController *target; diff --git a/Source/NimbleCommander/NimbleCommander/States/FilePanels/NCPanelOpenWithMenuDelegate.mm b/Source/NimbleCommander/NimbleCommander/States/FilePanels/NCPanelOpenWithMenuDelegate.mm index 863a52133..36120dd82 100644 --- a/Source/NimbleCommander/NimbleCommander/States/FilePanels/NCPanelOpenWithMenuDelegate.mm +++ b/Source/NimbleCommander/NimbleCommander/States/FilePanels/NCPanelOpenWithMenuDelegate.mm @@ -110,9 +110,9 @@ + (NSString *)alwaysOpenWithMenuIdentifier return @"always"; } -- (void)setContextSource:(const std::vector)_items +- (void)setContextSource:(const std::vector&)_items { - m_ContextItems = std::move(_items); + m_ContextItems = _items; } - (BOOL)menuHasKeyEquivalent:(NSMenu *) [[maybe_unused]] _menu diff --git a/Source/Panel/source/ExternalTools.mm b/Source/Panel/source/ExternalTools.mm index 9e98f4391..6bb7eae49 100644 --- a/Source/Panel/source/ExternalTools.mm +++ b/Source/Panel/source/ExternalTools.mm @@ -43,13 +43,13 @@ void ExternalToolsParameters::InsertCurrentItem(CurrentItem _ci, bool _partial) { m_Steps.emplace_back(ActionType::CurrentItem, m_CurrentItems.size(), _partial); - m_CurrentItems.emplace_back(std::move(_ci)); + m_CurrentItems.emplace_back(_ci); } void ExternalToolsParameters::InsertSelectedItem(SelectedItems _si, bool _partial) { m_Steps.emplace_back(ActionType::SelectedItems, m_SelectedItems.size(), _partial); - m_SelectedItems.emplace_back(std::move(_si)); + m_SelectedItems.emplace_back(_si); } std::span ExternalToolsParameters::Steps() const noexcept @@ -344,10 +344,10 @@ result.InsertValueRequirement(std::move(*val), partial); } if( auto val = std::get_if(¶m) ) { - result.InsertCurrentItem(std::move(*val), partial); + result.InsertCurrentItem(*val, partial); } if( auto val = std::get_if(¶m) ) { - result.InsertSelectedItem(std::move(*val), partial); + result.InsertSelectedItem(*val, partial); } if( auto val = std::get_if(¶m) ) { result.m_MaximumTotalFiles = val->maximum; diff --git a/Source/Panel/source/PanelData.mm b/Source/Panel/source/PanelData.mm index a403e15b8..9621a8168 100644 --- a/Source/Panel/source/PanelData.mm +++ b/Source/Panel/source/PanelData.mm @@ -215,7 +215,7 @@ static void UpdateWithExisingVD(ItemVolatileData &_new_vd, const ItemVolatileDat throw std::invalid_argument("PanelData::ReLoad: incompatible listing type!"); // put a new data in a place - m_Listing = std::move(_listing); + m_Listing = _listing; m_VolatileData = std::move(new_vd); m_EntriesByRawName = std::move(dirbyrawcname); diff --git a/Source/Panel/tests/PanelData_UT.mm b/Source/Panel/tests/PanelData_UT.mm index be87eb80c..73c253ae6 100644 --- a/Source/Panel/tests/PanelData_UT.mm +++ b/Source/Panel/tests/PanelData_UT.mm @@ -232,7 +232,7 @@ static VFSListingPtr ProduceDummyListing(const std::vectorItem(0).FilenameC()) == 0); CHECK(data.SortedIndexForName(listing->Item(2).FilenameC()) == 1); diff --git a/Source/Term/source/ShellTask.cpp b/Source/Term/source/ShellTask.cpp index 22aa7c85b..4d0b1e303 100644 --- a/Source/Term/source/ShellTask.cpp +++ b/Source/Term/source/ShellTask.cpp @@ -181,7 +181,7 @@ static std::optional TryToResolve(const std::filesystem:: if( ec == std::error_code{} && exists ) { const bool is_symlink = std::filesystem::is_symlink(_path, ec); if( ec == std::error_code{} && is_symlink ) { - const auto symlink = std::filesystem::read_symlink(_path, ec); + auto symlink = std::filesystem::read_symlink(_path, ec); if( ec != std::error_code{} ) return {}; if( symlink.is_absolute() ) diff --git a/Source/Utility/source/FSEventsFileUpdateImpl.cpp b/Source/Utility/source/FSEventsFileUpdateImpl.cpp index a98a1ed8c..778a1beff 100644 --- a/Source/Utility/source/FSEventsFileUpdateImpl.cpp +++ b/Source/Utility/source/FSEventsFileUpdateImpl.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2021-2023 Michael Kazakov. Subject to GNU General Public License version 3. +// Copyright (C) 2021-2024 Michael Kazakov. Subject to GNU General Public License version 3. #include "FSEventsFileUpdateImpl.h" #include #include @@ -235,8 +235,9 @@ void FSEventsFileUpdateImpl::KickstartBackgroundScanner() } } - dispatch_to_background( - [paths = std::move(paths), context = m_WeakAsyncContext] { BackgroundScanner(std::move(paths), context); }); + dispatch_to_background([paths = std::move(paths), context = m_WeakAsyncContext] mutable { + BackgroundScanner(std::move(paths), context); + }); } void FSEventsFileUpdateImpl::AcceptScannedStats(const std::vector &_paths, diff --git a/Source/VFS/source/Host.cpp b/Source/VFS/source/Host.cpp index be47f0172..ade2ec097 100644 --- a/Source/VFS/source/Host.cpp +++ b/Source/VFS/source/Host.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2013-2023 Michael Kazakov. Subject to GNU General Public License version 3. +// Copyright (C) 2013-2024 Michael Kazakov. Subject to GNU General Public License version 3. #include #include "ListingInput.h" #include "../include/VFS/Host.h" @@ -68,7 +68,7 @@ FileObservationToken::FileObservationToken(unsigned long _token, std::weak_ptrCommitProcs(std::move(procs)); }); diff --git a/Source/Viewer/source/Highlighting/Client.cpp b/Source/Viewer/source/Highlighting/Client.cpp index 40c096f76..d9298890b 100644 --- a/Source/Viewer/source/Highlighting/Client.cpp +++ b/Source/Viewer/source/Highlighting/Client.cpp @@ -1,10 +1,10 @@ // Copyright (C) 2024 Michael Kazakov. Subject to GNU General Public License version 3. +#include #include #include -#include -#include -#include +#include #include +#include namespace nc::viewer::hl { diff --git a/Source/Viewer/source/Highlighting/Document.cpp b/Source/Viewer/source/Highlighting/Document.cpp index ca9c28220..b9d2e3ccd 100644 --- a/Source/Viewer/source/Highlighting/Document.cpp +++ b/Source/Viewer/source/Highlighting/Document.cpp @@ -1,9 +1,9 @@ // Copyright (C) 2024 Michael Kazakov. Subject to GNU General Public License version 3. #include -#include #include +#include +#include #include -#include namespace nc::viewer::hl { diff --git a/Source/Viewer/source/Highlighting/Highlighter.cpp b/Source/Viewer/source/Highlighting/Highlighter.cpp index b5246186a..3fca1b4eb 100644 --- a/Source/Viewer/source/Highlighting/Highlighter.cpp +++ b/Source/Viewer/source/Highlighting/Highlighter.cpp @@ -1,17 +1,18 @@ // Copyright (C) 2024 Michael Kazakov. Subject to GNU General Public License version 3. -#include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include #include +#include // NOLINT +#include // NOLINT +#include // NOLINT +#include // NOLINT +#include // NOLINT +#include // NOLINT +#include // NOLINT +#include // NOLINT + namespace nc::viewer::hl { Highlighter::Highlighter(LexerSettings _settings) : m_Settings(std::move(_settings)) diff --git a/Source/Viewer/source/Highlighting/Service.cpp b/Source/Viewer/source/Highlighting/Service.cpp index f2869c5b1..cd86998b5 100644 --- a/Source/Viewer/source/Highlighting/Service.cpp +++ b/Source/Viewer/source/Highlighting/Service.cpp @@ -1,10 +1,11 @@ // Copyright (C) 2024 Michael Kazakov. Subject to GNU General Public License version 3. -#include -#include -#include -#include +#include // NOLINT +#include // NOLINT + +#include #include -#include +#include +#include #include static void send_reply_error(xpc_connection_t _peer, xpc_object_t _from_event, const std::string &_error_msg) noexcept diff --git a/Source/Viewer/source/TextModeWorkingSetHighlighting.cpp b/Source/Viewer/source/TextModeWorkingSetHighlighting.cpp index a25b858d6..7bfe08197 100644 --- a/Source/Viewer/source/TextModeWorkingSetHighlighting.cpp +++ b/Source/Viewer/source/TextModeWorkingSetHighlighting.cpp @@ -2,11 +2,11 @@ #include "TextModeWorkingSetHighlighting.h" #include "Highlighting/Client.h" #include "Log.h" -#include -#include #include +#include +#include +#include #include -#include namespace nc::viewer { diff --git a/Source/Viewer/tests/hlHighlighter_UT.cpp b/Source/Viewer/tests/hlHighlighter_UT.cpp index de1dba905..d7bcd2848 100644 --- a/Source/Viewer/tests/hlHighlighter_UT.cpp +++ b/Source/Viewer/tests/hlHighlighter_UT.cpp @@ -23,7 +23,7 @@ TEST_CASE(PREFIX "Regular use with C++ lexer") { LexerSettings set; set.name = "cpp"; - set.wordlists.push_back("int"); + set.wordlists.emplace_back("int"); set.mapping.SetMapping(SCE_C_DEFAULT, Style::Default); set.mapping.SetMapping(SCE_C_COMMENT, Style::Comment); set.mapping.SetMapping(SCE_C_COMMENTLINE, Style::Comment); @@ -95,7 +95,7 @@ TEST_CASE(PREFIX "Regular use with Bash lexer") { LexerSettings set; set.name = "bash"; - set.wordlists.push_back("set if command then echo exit fi export"); + set.wordlists.emplace_back("set if command then echo exit fi export"); set.mapping.SetMapping(SCE_SH_DEFAULT, Style::Default); set.mapping.SetMapping(SCE_SH_ERROR, Style::Default); set.mapping.SetMapping(SCE_SH_COMMENTLINE, Style::Comment);