From 31b64848e31d8eb329bd04d865c9f517288d543f Mon Sep 17 00:00:00 2001 From: eidheim Date: Sun, 20 May 2018 12:19:42 +0200 Subject: [PATCH] Fixed most of clang-tidy's performance checks --- src/cmake.cc | 4 ++-- src/ctags.cc | 2 +- src/ctags.h | 2 +- src/debug_lldb.cc | 3 +++ src/directories.cc | 11 ++++++----- src/directories.h | 4 ++-- src/documentation_cppreference.cc | 2 +- src/documentation_cppreference.h | 2 +- src/menu.cc | 2 +- src/menu.h | 2 +- src/meson.cc | 2 +- src/notebook.cc | 2 +- src/notebook.h | 2 +- src/selection_dialog.cc | 8 ++++---- src/selection_dialog.h | 10 +++++----- src/source.cc | 4 ++-- src/source.h | 4 ++-- src/source_base.cc | 8 ++++---- src/source_base.h | 8 ++++---- src/source_clang.cc | 10 +++++----- src/source_clang.h | 8 ++++---- src/source_diff.cc | 2 +- src/source_diff.h | 2 +- src/source_language_protocol.cc | 26 +++++++++++++------------- src/source_language_protocol.h | 2 +- src/source_spellcheck.cc | 2 +- src/source_spellcheck.h | 2 +- src/terminal.cc | 4 ++-- src/terminal.h | 4 ++-- tests/stubs/directories.cc | 2 +- tests/stubs/selection_dialog.cc | 6 +++--- 31 files changed, 78 insertions(+), 74 deletions(-) diff --git a/src/cmake.cc b/src/cmake.cc index 973ac6a..1d23a31 100644 --- a/src/cmake.cc +++ b/src/cmake.cc @@ -272,11 +272,11 @@ void CMake::parse_variable_parameters(std::string &data) { //Remove variables we do not know: pos=data.find("${"); - auto pos_end=data.find("}", pos+2); + auto pos_end=data.find('}', pos+2); while(pos!=std::string::npos && pos_end!=std::string::npos) { data.erase(pos, pos_end-pos+1); pos=data.find("${"); - pos_end=data.find("}", pos+2); + pos_end=data.find('}', pos+2); } } diff --git a/src/ctags.cc b/src/ctags.cc index d2f8f88..55b9fb4 100644 --- a/src/ctags.cc +++ b/src/ctags.cc @@ -100,7 +100,7 @@ Ctags::Location Ctags::get_location(const std::string &line, bool markup) { } ///Split up a type into its various significant parts -std::vector Ctags::get_type_parts(const std::string type) { +std::vector Ctags::get_type_parts(const std::string &type) { std::vector parts; size_t text_start=-1; for(size_t c=0;c get_locations(const boost::filesystem::path &path, const std::string &name, const std::string &type); private: - static std::vector get_type_parts(const std::string type); + static std::vector get_type_parts(const std::string &type); }; diff --git a/src/debug_lldb.cc b/src/debug_lldb.cc index ece42c3..71b1d3c 100644 --- a/src/debug_lldb.cc +++ b/src/debug_lldb.cc @@ -103,6 +103,7 @@ void Debug::LLDB::start(const std::string &command, const boost::filesystem::pat auto &arguments=std::get<2>(parsed_run_arguments); std::vector argv; + argv.reserve(arguments.size()); for(auto &argument : arguments) argv.emplace_back(argument.c_str()); argv.emplace_back(nullptr); @@ -149,6 +150,7 @@ void Debug::LLDB::start(const std::string &command, const boost::filesystem::pat // Create environment array std::vector environment; + environment.reserve(environment_from_arguments.size()); for(auto &e: environment_from_arguments) environment.emplace_back(e.c_str()); environment.emplace_back(nullptr); @@ -160,6 +162,7 @@ void Debug::LLDB::start(const std::string &command, const boost::filesystem::pat else { // Create environment array std::vector environment; + environment.reserve(environment_from_arguments.size()); for(auto &e: environment_from_arguments) environment.emplace_back(e.c_str()); size_t environ_size=0; diff --git a/src/directories.cc b/src/directories.cc index 0ceb032..f844949 100644 --- a/src/directories.cc +++ b/src/directories.cc @@ -394,7 +394,7 @@ void Directories::update() { add_or_update_path(directory.first, directory.second, false); } -void Directories::on_save_file(boost::filesystem::path file_path) { +void Directories::on_save_file(const boost::filesystem::path &file_path) { auto it=directories.find(file_path.parent_path().string()); if(it!=directories.end()) { if(it->second.repository) @@ -639,8 +639,9 @@ void Directories::remove_path(const boost::filesystem::path &dir_path) { } } -void Directories::colorize_path(const boost::filesystem::path &dir_path, bool include_parent_paths) { - auto it=directories.find(dir_path.string()); +void Directories::colorize_path(boost::filesystem::path dir_path_, bool include_parent_paths) { + auto dir_path=std::make_shared(std::move(dir_path_)); + auto it=directories.find(dir_path->string()); if(it==directories.end()) return; @@ -655,8 +656,8 @@ void Directories::colorize_path(const boost::filesystem::path &dir_path, bool in Terminal::get().async_print(std::string("Error (git): ")+e.what()+'\n', true); } - dispatcher.post([this, dir_path=std::move(dir_path), include_parent_paths, status=std::move(status)] { - auto it=directories.find(dir_path.string()); + dispatcher.post([this, dir_path, include_parent_paths, status=std::move(status)] { + auto it=directories.find(dir_path->string()); if(it==directories.end()) return; diff --git a/src/directories.h b/src/directories.h index 53d768f..73c2861 100644 --- a/src/directories.h +++ b/src/directories.h @@ -60,7 +60,7 @@ public: void open(const boost::filesystem::path &dir_path=""); void update(); - void on_save_file(boost::filesystem::path file_path); + void on_save_file(const boost::filesystem::path &file_path); void select(const boost::filesystem::path &path); boost::filesystem::path path; @@ -71,7 +71,7 @@ protected: private: void add_or_update_path(const boost::filesystem::path &dir_path, const Gtk::TreeModel::Row &row, bool include_parent_paths); void remove_path(const boost::filesystem::path &dir_path); - void colorize_path(const boost::filesystem::path &dir_path, bool include_parent_paths); + void colorize_path(boost::filesystem::path dir_path_, bool include_parent_paths); Glib::RefPtr tree_store; TreeStore::ColumnRecord column_record; diff --git a/src/documentation_cppreference.cc b/src/documentation_cppreference.cc index 060e791..fe132ea 100644 --- a/src/documentation_cppreference.cc +++ b/src/documentation_cppreference.cc @@ -1,7 +1,7 @@ #include "documentation_cppreference.h" #include -std::string Documentation::CppReference::get_url(const std::string symbol) noexcept { +std::string Documentation::CppReference::get_url(const std::string &symbol) noexcept { // Copied from http://upload.cppreference.com/mwiki/images/d/df/html_book_20170409.zip/reference/cppreference-export-ns0,4,8,10.xml // Using raw string instead of map to reduce compile time const static std::string symbol_urls = R"(size_t c/types/size_t diff --git a/src/documentation_cppreference.h b/src/documentation_cppreference.h index 7a61f83..5c0bd0c 100644 --- a/src/documentation_cppreference.h +++ b/src/documentation_cppreference.h @@ -4,6 +4,6 @@ namespace Documentation { class CppReference { public: - static std::string get_url(const std::string symbol) noexcept; + static std::string get_url(const std::string &symbol) noexcept; }; } diff --git a/src/menu.cc b/src/menu.cc index a79d156..8246d53 100644 --- a/src/menu.cc +++ b/src/menu.cc @@ -477,7 +477,7 @@ const Glib::ustring menu_xml= R"RAW( )RAW"; -void Menu::add_action(const std::string &name, std::function action) { +void Menu::add_action(const std::string &name, const std::function &action) { auto g_application=g_application_get_default(); auto gio_application=Glib::wrap(g_application, true); auto application=Glib::RefPtr::cast_static(gio_application); diff --git a/src/menu.h b/src/menu.h index 9a3c9ad..f1afec4 100644 --- a/src/menu.h +++ b/src/menu.h @@ -12,7 +12,7 @@ public: return singleton; } - void add_action(const std::string &name, std::function action); + void add_action(const std::string &name, const std::function &action); std::unordered_map > actions; void set_keys(); diff --git a/src/meson.cc b/src/meson.cc index 42516f6..45ab739 100644 --- a/src/meson.cc +++ b/src/meson.cc @@ -95,7 +95,7 @@ boost::filesystem::path Meson::get_executable(const boost::filesystem::path &bui auto values=command.parameter_values("-o"); if(!values.empty()) { size_t pos; - if((pos=values[0].find("@"))!=std::string::npos) { + if((pos=values[0].find('@'))!=std::string::npos) { if(pos+1 on_close) { +Notebook::TabLabel::TabLabel(const std::function &on_close) { set_can_focus(false); auto button=Gtk::manage(new Gtk::Button()); diff --git a/src/notebook.h b/src/notebook.h index 6798f4c..5aae90f 100644 --- a/src/notebook.h +++ b/src/notebook.h @@ -9,7 +9,7 @@ class Notebook : public Gtk::Paned { class TabLabel : public Gtk::EventBox { public: - TabLabel(std::function on_close); + TabLabel(const std::function &on_close); Gtk::Label label; }; diff --git a/src/selection_dialog.cc b/src/selection_dialog.cc index dd8ae62..aed3bda 100644 --- a/src/selection_dialog.cc +++ b/src/selection_dialog.cc @@ -36,8 +36,8 @@ void SelectionDialogBase::ListViewText::clear() { size=0; } -SelectionDialogBase::SelectionDialogBase(Gtk::TextView *text_view, Glib::RefPtr start_mark_, bool show_search_entry, bool use_markup): - start_mark(std::move(start_mark_)), text_view(text_view), window(Gtk::WindowType::WINDOW_POPUP), vbox(Gtk::Orientation::ORIENTATION_VERTICAL), list_view_text(use_markup), show_search_entry(show_search_entry) { +SelectionDialogBase::SelectionDialogBase(Gtk::TextView *text_view, const Glib::RefPtr &start_mark, bool show_search_entry, bool use_markup): + start_mark(start_mark), text_view(text_view), window(Gtk::WindowType::WINDOW_POPUP), vbox(Gtk::Orientation::ORIENTATION_VERTICAL), list_view_text(use_markup), show_search_entry(show_search_entry) { auto g_application=g_application_get_default(); auto gio_application=Glib::wrap(g_application, true); auto application=Glib::RefPtr::cast_static(gio_application); @@ -195,7 +195,7 @@ void SelectionDialogBase::hide() { std::unique_ptr SelectionDialog::instance; -SelectionDialog::SelectionDialog(Gtk::TextView *text_view, Glib::RefPtr start_mark, bool show_search_entry, bool use_markup) : SelectionDialogBase(text_view, start_mark, show_search_entry, use_markup) { +SelectionDialog::SelectionDialog(Gtk::TextView *text_view, const Glib::RefPtr &start_mark, bool show_search_entry, bool use_markup) : SelectionDialogBase(text_view, start_mark, show_search_entry, use_markup) { auto search_key=std::make_shared(); auto filter_model=Gtk::TreeModelFilter::create(list_view_text.get_model()); @@ -322,7 +322,7 @@ bool SelectionDialog::on_key_press(GdkEventKey* key) { std::unique_ptr CompletionDialog::instance; -CompletionDialog::CompletionDialog(Gtk::TextView *text_view, Glib::RefPtr start_mark) : SelectionDialogBase(text_view, start_mark, false, false) { +CompletionDialog::CompletionDialog(Gtk::TextView *text_view, const Glib::RefPtr &start_mark) : SelectionDialogBase(text_view, start_mark, false, false) { show_offset=text_view->get_buffer()->get_insert()->get_iter().get_offset(); auto search_key=std::make_shared(); diff --git a/src/selection_dialog.h b/src/selection_dialog.h index c8747a3..cf61f1a 100644 --- a/src/selection_dialog.h +++ b/src/selection_dialog.h @@ -34,7 +34,7 @@ class SelectionDialogBase { }; public: - SelectionDialogBase(Gtk::TextView *text_view, Glib::RefPtr start_mark_, bool show_search_entry, bool use_markup); + SelectionDialogBase(Gtk::TextView *text_view, const Glib::RefPtr &start_mark, bool show_search_entry, bool use_markup); virtual ~SelectionDialogBase(); void add_row(const std::string& row); void erase_rows(); @@ -67,12 +67,12 @@ protected: }; class SelectionDialog : public SelectionDialogBase { - SelectionDialog(Gtk::TextView *text_view, Glib::RefPtr start_mark, bool show_search_entry, bool use_markup); + SelectionDialog(Gtk::TextView *text_view, const Glib::RefPtr &start_mark, bool show_search_entry, bool use_markup); static std::unique_ptr instance; public: bool on_key_press(GdkEventKey* key); - static void create(Gtk::TextView *text_view, Glib::RefPtr start_mark, bool show_search_entry=true, bool use_markup=false) { + static void create(Gtk::TextView *text_view, const Glib::RefPtr &start_mark, bool show_search_entry=true, bool use_markup=false) { instance=std::unique_ptr(new SelectionDialog(text_view, start_mark, show_search_entry, use_markup)); } static void create(bool show_search_entry=true, bool use_markup=false) { @@ -82,13 +82,13 @@ public: }; class CompletionDialog : public SelectionDialogBase { - CompletionDialog(Gtk::TextView *text_view, Glib::RefPtr start_mark); + CompletionDialog(Gtk::TextView *text_view, const Glib::RefPtr &start_mark); static std::unique_ptr instance; public: bool on_key_release(GdkEventKey* key); bool on_key_press(GdkEventKey* key); - static void create(Gtk::TextView *text_view, Glib::RefPtr start_mark) { + static void create(Gtk::TextView *text_view, const Glib::RefPtr &start_mark) { instance=std::unique_ptr(new CompletionDialog(text_view, start_mark)); } static std::unique_ptr &get() {return instance;} diff --git a/src/source.cc b/src/source.cc index 81aad22..6e5d40b 100644 --- a/src/source.cc +++ b/src/source.cc @@ -114,7 +114,7 @@ std::string Source::FixIt::string(const Glib::RefPtr &buffer) { std::unordered_set Source::View::non_deleted_views; std::unordered_set Source::View::views; -Source::View::View(const boost::filesystem::path &file_path, Glib::RefPtr language, bool is_generic_view): BaseView(file_path, language), SpellCheckView(file_path, language), DiffView(file_path, language) { +Source::View::View(const boost::filesystem::path &file_path, const Glib::RefPtr &language, bool is_generic_view): BaseView(file_path, language), SpellCheckView(file_path, language), DiffView(file_path, language) { non_deleted_views.emplace(this); views.emplace(this); @@ -2893,7 +2893,7 @@ std::pair Source::View::find_tab_char_and_size() { ///////////////////// //// GenericView //// ///////////////////// -Source::GenericView::GenericView(const boost::filesystem::path &file_path, Glib::RefPtr language) : BaseView(file_path, language), View(file_path, language, true) { +Source::GenericView::GenericView(const boost::filesystem::path &file_path, const Glib::RefPtr &language) : BaseView(file_path, language), View(file_path, language, true) { configure(); spellcheck_all=true; diff --git a/src/source.h b/src/source.h index 026bd4f..16a23f8 100644 --- a/src/source.h +++ b/src/source.h @@ -53,7 +53,7 @@ namespace Source { static std::unordered_set non_deleted_views; static std::unordered_set views; - View(const boost::filesystem::path &file_path, Glib::RefPtr language, bool is_generic_view=false); + View(const boost::filesystem::path &file_path, const Glib::RefPtr &language, bool is_generic_view=false); ~View() override; bool save() override; @@ -169,7 +169,7 @@ namespace Source { static Glib::RefPtr create() {return Glib::RefPtr(new CompletionBuffer());} }; public: - GenericView(const boost::filesystem::path &file_path, Glib::RefPtr language); + GenericView(const boost::filesystem::path &file_path, const Glib::RefPtr &language); void parse_language_file(Glib::RefPtr &completion_buffer, bool &has_context_class, const boost::property_tree::ptree &pt); }; diff --git a/src/source_base.cc b/src/source_base.cc index ff4c884..25c293b 100644 --- a/src/source_base.cc +++ b/src/source_base.cc @@ -5,7 +5,7 @@ #include "config.h" #include -Source::BaseView::BaseView(boost::filesystem::path file_path_, Glib::RefPtr language_): Gsv::View(), file_path(std::move(file_path_)), language(std::move(language_)), status_diagnostics(0, 0, 0) { +Source::BaseView::BaseView(const boost::filesystem::path &file_path, const Glib::RefPtr &language): Gsv::View(), file_path(file_path), language(language), status_diagnostics(0, 0, 0) { load(true); get_buffer()->place_cursor(get_buffer()->get_iter_at_offset(0)); @@ -337,7 +337,7 @@ std::string Source::BaseView::get_line(const Gtk::TextIter &iter) { std::string line(get_buffer()->get_text(line_start_it, line_end_it)); return line; } -std::string Source::BaseView::get_line(Glib::RefPtr mark) { +std::string Source::BaseView::get_line(const Glib::RefPtr &mark) { return get_line(mark->get_iter()); } std::string Source::BaseView::get_line(int line_nr) { @@ -352,7 +352,7 @@ std::string Source::BaseView::get_line_before(const Gtk::TextIter &iter) { std::string line(get_buffer()->get_text(line_it, iter)); return line; } -std::string Source::BaseView::get_line_before(Glib::RefPtr mark) { +std::string Source::BaseView::get_line_before(const Glib::RefPtr &mark) { return get_line_before(mark->get_iter()); } std::string Source::BaseView::get_line_before() { @@ -362,7 +362,7 @@ std::string Source::BaseView::get_line_before() { Gtk::TextIter Source::BaseView::get_tabs_end_iter(const Gtk::TextIter &iter) { return get_tabs_end_iter(iter.get_line()); } -Gtk::TextIter Source::BaseView::get_tabs_end_iter(Glib::RefPtr mark) { +Gtk::TextIter Source::BaseView::get_tabs_end_iter(const Glib::RefPtr &mark) { return get_tabs_end_iter(mark->get_iter()); } Gtk::TextIter Source::BaseView::get_tabs_end_iter(int line_nr) { diff --git a/src/source_base.h b/src/source_base.h index 1141894..3307f4b 100644 --- a/src/source_base.h +++ b/src/source_base.h @@ -8,7 +8,7 @@ namespace Source { class BaseView : public Gsv::View { public: - BaseView(boost::filesystem::path file_path_, Glib::RefPtr language_); + BaseView(const boost::filesystem::path &file_path, const Glib::RefPtr &language); ~BaseView() override; boost::filesystem::path file_path; @@ -61,14 +61,14 @@ namespace Source { Gtk::TextIter get_smart_end_iter(const Gtk::TextIter &iter); std::string get_line(const Gtk::TextIter &iter); - std::string get_line(Glib::RefPtr mark); + std::string get_line(const Glib::RefPtr &mark); std::string get_line(int line_nr); std::string get_line(); std::string get_line_before(const Gtk::TextIter &iter); - std::string get_line_before(Glib::RefPtr mark); + std::string get_line_before(const Glib::RefPtr &mark); std::string get_line_before(); Gtk::TextIter get_tabs_end_iter(const Gtk::TextIter &iter); - Gtk::TextIter get_tabs_end_iter(Glib::RefPtr mark); + Gtk::TextIter get_tabs_end_iter(const Glib::RefPtr &mark); Gtk::TextIter get_tabs_end_iter(int line_nr); Gtk::TextIter get_tabs_end_iter(); diff --git a/src/source_clang.cc b/src/source_clang.cc index d7bad23..06917ad 100644 --- a/src/source_clang.cc +++ b/src/source_clang.cc @@ -16,7 +16,7 @@ clangmm::Index Source::ClangViewParse::clang_index(0, 0); -Source::ClangViewParse::ClangViewParse(const boost::filesystem::path &file_path, Glib::RefPtr language): +Source::ClangViewParse::ClangViewParse(const boost::filesystem::path &file_path, const Glib::RefPtr &language): BaseView(file_path, language), Source::View(file_path, language) { Usages::Clang::erase_cache(file_path); @@ -441,7 +441,7 @@ void Source::ClangViewParse::show_type_tooltips(const Gdk::Rectangle &rectangle) } -Source::ClangViewAutocomplete::ClangViewAutocomplete(const boost::filesystem::path &file_path, Glib::RefPtr language): +Source::ClangViewAutocomplete::ClangViewAutocomplete(const boost::filesystem::path &file_path, const Glib::RefPtr &language): BaseView(file_path, language), Source::ClangViewParse(file_path, language), autocomplete(this, interactive_completion, last_keyval, true) { non_interactive_completion=[this] { if(CompletionDialog::get() && CompletionDialog::get()->is_visible()) @@ -816,7 +816,7 @@ const std::unordered_map &Source::ClangViewAutocomplet } -Source::ClangViewRefactor::ClangViewRefactor(const boost::filesystem::path &file_path, Glib::RefPtr language) : +Source::ClangViewRefactor::ClangViewRefactor(const boost::filesystem::path &file_path, const Glib::RefPtr &language) : BaseView(file_path, language), Source::ClangViewParse(file_path, language) { similar_identifiers_tag=get_buffer()->create_tag(); similar_identifiers_tag->property_weight()=Pango::WEIGHT_ULTRAHEAVY; @@ -1502,7 +1502,7 @@ Source::ClangViewRefactor::ClangViewRefactor(const boost::filesystem::path &file std::string method; if(kind!=clangmm::Cursor::Kind::Constructor && kind!=clangmm::Cursor::Kind::Destructor) { method+=cursor.get_type().get_result().get_spelling(); - auto pos=method.find(" "); + auto pos=method.find(' '); if(pos!=std::string::npos) method.erase(pos, 1); method+=" "; @@ -1744,7 +1744,7 @@ void Source::ClangViewRefactor::tag_similar_identifiers(const Identifier &identi } -Source::ClangView::ClangView(const boost::filesystem::path &file_path, Glib::RefPtr language): +Source::ClangView::ClangView(const boost::filesystem::path &file_path, const Glib::RefPtr& language): BaseView(file_path, language), ClangViewParse(file_path, language), ClangViewAutocomplete(file_path, language), ClangViewRefactor(file_path, language) { if(language) { get_source_buffer()->set_highlight_syntax(true); diff --git a/src/source_clang.h b/src/source_clang.h index c7e1aaa..3aca95e 100644 --- a/src/source_clang.h +++ b/src/source_clang.h @@ -16,7 +16,7 @@ namespace Source { enum class ParseProcessState {IDLE, STARTING, PREPROCESSING, PROCESSING, POSTPROCESSING}; public: - ClangViewParse(const boost::filesystem::path &file_path, Glib::RefPtr language); + ClangViewParse(const boost::filesystem::path &file_path, const Glib::RefPtr &language); bool save() override; void configure() override; @@ -55,7 +55,7 @@ namespace Source { class ClangViewAutocomplete : public virtual ClangViewParse { public: - ClangViewAutocomplete(const boost::filesystem::path &file_path, Glib::RefPtr language); + ClangViewAutocomplete(const boost::filesystem::path &file_path, const Glib::RefPtr &language); protected: Autocomplete autocomplete; std::unique_ptr code_complete_results; @@ -84,7 +84,7 @@ namespace Source { clangmm::Cursor cursor; }; public: - ClangViewRefactor(const boost::filesystem::path &file_path, Glib::RefPtr language); + ClangViewRefactor(const boost::filesystem::path &file_path, const Glib::RefPtr &language); private: Identifier get_identifier(); void wait_parsing(); @@ -97,7 +97,7 @@ namespace Source { class ClangView : public ClangViewAutocomplete, public ClangViewRefactor { public: - ClangView(const boost::filesystem::path &file_path, Glib::RefPtr language); + ClangView(const boost::filesystem::path &file_path, const Glib::RefPtr &language); void full_reparse() override; void async_delete(); diff --git a/src/source_diff.cc b/src/source_diff.cc index a012b27..df4df20 100644 --- a/src/source_diff.cc +++ b/src/source_diff.cc @@ -34,7 +34,7 @@ void Source::DiffView::Renderer::draw_vfunc(const Cairo::RefPtr } } -Source::DiffView::DiffView(const boost::filesystem::path &file_path, Glib::RefPtr language) : BaseView(file_path, language), renderer(new Renderer()) { +Source::DiffView::DiffView(const boost::filesystem::path &file_path, const Glib::RefPtr &language) : BaseView(file_path, language), renderer(new Renderer()) { boost::system::error_code ec; canonical_file_path=boost::filesystem::canonical(file_path, ec); if(ec) diff --git a/src/source_diff.h b/src/source_diff.h index ed37d0b..c146563 100644 --- a/src/source_diff.h +++ b/src/source_diff.h @@ -29,7 +29,7 @@ namespace Source { Gsv::GutterRendererState p6) override; }; public: - DiffView(const boost::filesystem::path &file_path, Glib::RefPtr language); + DiffView(const boost::filesystem::path &file_path, const Glib::RefPtr &language); ~DiffView() override; void configure() override; diff --git a/src/source_language_protocol.cc b/src/source_language_protocol.cc index 94e23cd..3057c51 100644 --- a/src/source_language_protocol.cc +++ b/src/source_language_protocol.cc @@ -317,7 +317,7 @@ void LanguageProtocol::Client::handle_server_request(const std::string &method, } } -Source::LanguageProtocolView::LanguageProtocolView(const boost::filesystem::path &file_path, Glib::RefPtr language, std::string language_id_) +Source::LanguageProtocolView::LanguageProtocolView(const boost::filesystem::path &file_path, const Glib::RefPtr &language, std::string language_id_) : Source::BaseView(file_path, language), Source::View(file_path, language), uri("file://"+file_path.string()), language_id(std::move(language_id_)), client(LanguageProtocol::Client::get(file_path, language_id)), autocomplete(this, interactive_completion, last_keyval, false) { configure(); get_source_buffer()->set_language(language); @@ -958,37 +958,37 @@ void Source::LanguageProtocolView::show_type_tooltips(const Gdk::Rectangle &rect client->write_request(this, "textDocument/hover", R"("textDocument": {"uri":"file://)"+file_path.string()+R"("}, "position": {"line": )"+std::to_string(iter.get_line())+", \"character\": "+std::to_string(iter.get_line_offset())+"}", [this, offset, current_request](const boost::property_tree::ptree &result, bool error) { if(!error) { // hover result structure vary significantly from the different language servers - std::string content; + auto content=std::make_shared(); auto contents_pt=result.get_child("contents", boost::property_tree::ptree()); for(auto it=contents_pt.begin();it!=contents_pt.end();++it) { auto value=it->second.get("value", ""); if(!value.empty()) - content.insert(0, value+(content.empty()?"":"\n\n")); + content->insert(0, value+(content->empty()?"":"\n\n")); else { value=it->second.get_value(""); if(!value.empty()) - content+=(content.empty()?"":"\n\n")+value; + *content+=(content->empty()?"":"\n\n")+value; } } - if(content.empty()) { + if(content->empty()) { auto contents_it=result.find("contents"); if(contents_it!=result.not_found()) { - content=contents_it->second.get("value", ""); - if(content.empty()) - content=contents_it->second.get_value(""); + *content=contents_it->second.get("value", ""); + if(content->empty()) + *content=contents_it->second.get_value(""); } } - if(!content.empty()) { - while(!content.empty() && content.back()=='\n') { content.pop_back(); } // Remove unnecessary newlines - dispatcher.post([this, offset, content=std::move(content), current_request] { + if(!content->empty()) { + while(!content->empty() && content->back()=='\n') { content->pop_back(); } // Remove unnecessary newlines + dispatcher.post([this, offset, content, current_request] { if(current_request!=request_count) return; if(offset>=get_buffer()->get_char_count()) return; type_tooltips.clear(); - auto create_tooltip_buffer=[this, offset, content=std::move(content)]() { + auto create_tooltip_buffer=[this, offset, content]() { auto tooltip_buffer=Gtk::TextBuffer::create(get_buffer()->get_tag_table()); - tooltip_buffer->insert(tooltip_buffer->get_insert()->get_iter(), content); + tooltip_buffer->insert(tooltip_buffer->get_insert()->get_iter(), *content); #ifdef JUCI_ENABLE_DEBUG if(language_id=="rust" && capabilities.definition) { diff --git a/src/source_language_protocol.h b/src/source_language_protocol.h index 71e68c3..0c647bc 100644 --- a/src/source_language_protocol.h +++ b/src/source_language_protocol.h @@ -84,7 +84,7 @@ namespace LanguageProtocol { namespace Source { class LanguageProtocolView : public View { public: - LanguageProtocolView(const boost::filesystem::path &file_path, Glib::RefPtr language, std::string language_id_); + LanguageProtocolView(const boost::filesystem::path &file_path, const Glib::RefPtr &language, std::string language_id_); ~LanguageProtocolView() override; std::string uri; diff --git a/src/source_spellcheck.cc b/src/source_spellcheck.cc index f9247e4..84a6886 100644 --- a/src/source_spellcheck.cc +++ b/src/source_spellcheck.cc @@ -6,7 +6,7 @@ AspellConfig* Source::SpellCheckView::spellcheck_config=nullptr; -Source::SpellCheckView::SpellCheckView(const boost::filesystem::path &file_path, Glib::RefPtr language): BaseView(file_path, language) { +Source::SpellCheckView::SpellCheckView(const boost::filesystem::path &file_path, const Glib::RefPtr &language): BaseView(file_path, language) { if(spellcheck_config==nullptr) spellcheck_config=new_aspell_config(); spellcheck_checker=nullptr; diff --git a/src/source_spellcheck.h b/src/source_spellcheck.h index e5df4cc..eb8e949 100644 --- a/src/source_spellcheck.h +++ b/src/source_spellcheck.h @@ -5,7 +5,7 @@ namespace Source { class SpellCheckView : virtual public Source::BaseView { public: - SpellCheckView(const boost::filesystem::path &file_path, Glib::RefPtr language); + SpellCheckView(const boost::filesystem::path &file_path, const Glib::RefPtr &language); ~SpellCheckView() override; void configure() override; diff --git a/src/terminal.cc b/src/terminal.cc index 909c37d..3d885fb 100644 --- a/src/terminal.cc +++ b/src/terminal.cc @@ -77,7 +77,7 @@ int Terminal::process(std::istream &stdin_stream, std::ostream &stdout_stream, c return process.get_exit_status(); } -void Terminal::async_process(const std::string &command, const boost::filesystem::path &path, std::function callback, bool quiet) { +void Terminal::async_process(const std::string &command, const boost::filesystem::path &path, const std::function &callback, bool quiet) { std::thread async_execute_thread([this, command, path, callback, quiet]() { std::unique_lock processes_lock(processes_mutex); stdin_buffer.clear(); @@ -190,7 +190,7 @@ std::tuple Terminal::find return std::make_tuple(start_position, end_position, path, line_number, line_offset); } -void Terminal::apply_link_tags(Gtk::TextIter start_iter, Gtk::TextIter end_iter) { +void Terminal::apply_link_tags(const Gtk::TextIter &start_iter, const Gtk::TextIter &end_iter) { auto iter=start_iter; Gtk::TextIter line_start; bool line_start_set=false; diff --git a/src/terminal.h b/src/terminal.h index 8499cbd..53a4df4 100644 --- a/src/terminal.h +++ b/src/terminal.h @@ -18,7 +18,7 @@ public: int process(const std::string &command, const boost::filesystem::path &path="", bool use_pipes=true); int process(std::istream &stdin_stream, std::ostream &stdout_stream, const std::string &command, const boost::filesystem::path &path="", std::ostream *stderr_stream=nullptr); - void async_process(const std::string &command, const boost::filesystem::path &path="", std::function callback=nullptr, bool quiet=false); + void async_process(const std::string &command, const boost::filesystem::path &path="", const std::function &callback=nullptr, bool quiet=false); void kill_last_async_process(bool force=false); void kill_async_processes(bool force=false); @@ -42,7 +42,7 @@ private: size_t deleted_lines=0; std::tuple find_link(const std::string &line); - void apply_link_tags(Gtk::TextIter start_iter, Gtk::TextIter end_iter); + void apply_link_tags(const Gtk::TextIter &start_iter, const Gtk::TextIter &end_iter); std::vector> processes; std::mutex processes_mutex; diff --git a/tests/stubs/directories.cc b/tests/stubs/directories.cc index 9137faf..114be94 100644 --- a/tests/stubs/directories.cc +++ b/tests/stubs/directories.cc @@ -4,7 +4,7 @@ Directories::Directories() : ListViewText(1) {} Directories::~Directories() {} -void Directories::on_save_file(boost::filesystem::path file_path) {} +void Directories::on_save_file(const boost::filesystem::path &file_path) {} bool Directories::on_button_press_event(GdkEventButton *event) { return false; diff --git a/tests/stubs/selection_dialog.cc b/tests/stubs/selection_dialog.cc index 4d0c4ea..c392da3 100644 --- a/tests/stubs/selection_dialog.cc +++ b/tests/stubs/selection_dialog.cc @@ -2,7 +2,7 @@ SelectionDialogBase::ListViewText::ListViewText(bool use_markup) {} -SelectionDialogBase::SelectionDialogBase(Gtk::TextView *text_view, Glib::RefPtr start_mark, bool show_search_entry, bool use_markup): +SelectionDialogBase::SelectionDialogBase(Gtk::TextView *text_view, const Glib::RefPtr &start_mark, bool show_search_entry, bool use_markup): text_view(text_view), list_view_text(use_markup) {} void SelectionDialogBase::show() {} @@ -13,7 +13,7 @@ void SelectionDialogBase::add_row(const std::string& row) {} std::unique_ptr SelectionDialog::instance; -SelectionDialog::SelectionDialog(Gtk::TextView *text_view, Glib::RefPtr start_mark, bool show_search_entry, bool use_markup) : +SelectionDialog::SelectionDialog(Gtk::TextView *text_view, const Glib::RefPtr &start_mark, bool show_search_entry, bool use_markup) : SelectionDialogBase(text_view, start_mark, show_search_entry, use_markup) {} SelectionDialogBase::~SelectionDialogBase() {} @@ -22,7 +22,7 @@ bool SelectionDialog::on_key_press(GdkEventKey* key) { return true; } std::unique_ptr CompletionDialog::instance; -CompletionDialog::CompletionDialog(Gtk::TextView *text_view, Glib::RefPtr start_mark): +CompletionDialog::CompletionDialog(Gtk::TextView *text_view, const Glib::RefPtr &start_mark): SelectionDialogBase(text_view, start_mark, false, false) {} bool CompletionDialog::on_key_press(GdkEventKey* key) { return true;}