Skip to content
This repository was archived by the owner on Jun 25, 2020. It is now read-only.

Commit 31b6484

Browse files
committed
Fixed most of clang-tidy's performance checks
1 parent 8cfa234 commit 31b6484

31 files changed

+78
-74
lines changed

src/cmake.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,11 +272,11 @@ void CMake::parse_variable_parameters(std::string &data) {
272272

273273
//Remove variables we do not know:
274274
pos=data.find("${");
275-
auto pos_end=data.find("}", pos+2);
275+
auto pos_end=data.find('}', pos+2);
276276
while(pos!=std::string::npos && pos_end!=std::string::npos) {
277277
data.erase(pos, pos_end-pos+1);
278278
pos=data.find("${");
279-
pos_end=data.find("}", pos+2);
279+
pos_end=data.find('}', pos+2);
280280
}
281281
}
282282

src/ctags.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ Ctags::Location Ctags::get_location(const std::string &line, bool markup) {
100100
}
101101

102102
///Split up a type into its various significant parts
103-
std::vector<std::string> Ctags::get_type_parts(const std::string type) {
103+
std::vector<std::string> Ctags::get_type_parts(const std::string &type) {
104104
std::vector<std::string> parts;
105105
size_t text_start=-1;
106106
for(size_t c=0;c<type.size();++c) {

src/ctags.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@ class Ctags {
2323

2424
static std::vector<Location> get_locations(const boost::filesystem::path &path, const std::string &name, const std::string &type);
2525
private:
26-
static std::vector<std::string> get_type_parts(const std::string type);
26+
static std::vector<std::string> get_type_parts(const std::string &type);
2727
};

src/debug_lldb.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ void Debug::LLDB::start(const std::string &command, const boost::filesystem::pat
103103
auto &arguments=std::get<2>(parsed_run_arguments);
104104

105105
std::vector<const char*> argv;
106+
argv.reserve(arguments.size());
106107
for(auto &argument : arguments)
107108
argv.emplace_back(argument.c_str());
108109
argv.emplace_back(nullptr);
@@ -149,6 +150,7 @@ void Debug::LLDB::start(const std::string &command, const boost::filesystem::pat
149150

150151
// Create environment array
151152
std::vector<const char*> environment;
153+
environment.reserve(environment_from_arguments.size());
152154
for(auto &e: environment_from_arguments)
153155
environment.emplace_back(e.c_str());
154156
environment.emplace_back(nullptr);
@@ -160,6 +162,7 @@ void Debug::LLDB::start(const std::string &command, const boost::filesystem::pat
160162
else {
161163
// Create environment array
162164
std::vector<const char*> environment;
165+
environment.reserve(environment_from_arguments.size());
163166
for(auto &e: environment_from_arguments)
164167
environment.emplace_back(e.c_str());
165168
size_t environ_size=0;

src/directories.cc

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ void Directories::update() {
394394
add_or_update_path(directory.first, directory.second, false);
395395
}
396396

397-
void Directories::on_save_file(boost::filesystem::path file_path) {
397+
void Directories::on_save_file(const boost::filesystem::path &file_path) {
398398
auto it=directories.find(file_path.parent_path().string());
399399
if(it!=directories.end()) {
400400
if(it->second.repository)
@@ -639,8 +639,9 @@ void Directories::remove_path(const boost::filesystem::path &dir_path) {
639639
}
640640
}
641641

642-
void Directories::colorize_path(const boost::filesystem::path &dir_path, bool include_parent_paths) {
643-
auto it=directories.find(dir_path.string());
642+
void Directories::colorize_path(boost::filesystem::path dir_path_, bool include_parent_paths) {
643+
auto dir_path=std::make_shared<boost::filesystem::path>(std::move(dir_path_));
644+
auto it=directories.find(dir_path->string());
644645
if(it==directories.end())
645646
return;
646647

@@ -655,8 +656,8 @@ void Directories::colorize_path(const boost::filesystem::path &dir_path, bool in
655656
Terminal::get().async_print(std::string("Error (git): ")+e.what()+'\n', true);
656657
}
657658

658-
dispatcher.post([this, dir_path=std::move(dir_path), include_parent_paths, status=std::move(status)] {
659-
auto it=directories.find(dir_path.string());
659+
dispatcher.post([this, dir_path, include_parent_paths, status=std::move(status)] {
660+
auto it=directories.find(dir_path->string());
660661
if(it==directories.end())
661662
return;
662663

src/directories.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class Directories : public Gtk::ListViewText {
6060

6161
void open(const boost::filesystem::path &dir_path="");
6262
void update();
63-
void on_save_file(boost::filesystem::path file_path);
63+
void on_save_file(const boost::filesystem::path &file_path);
6464
void select(const boost::filesystem::path &path);
6565

6666
boost::filesystem::path path;
@@ -71,7 +71,7 @@ class Directories : public Gtk::ListViewText {
7171
private:
7272
void add_or_update_path(const boost::filesystem::path &dir_path, const Gtk::TreeModel::Row &row, bool include_parent_paths);
7373
void remove_path(const boost::filesystem::path &dir_path);
74-
void colorize_path(const boost::filesystem::path &dir_path, bool include_parent_paths);
74+
void colorize_path(boost::filesystem::path dir_path_, bool include_parent_paths);
7575

7676
Glib::RefPtr<Gtk::TreeStore> tree_store;
7777
TreeStore::ColumnRecord column_record;

src/documentation_cppreference.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include "documentation_cppreference.h"
22
#include <unordered_map>
33

4-
std::string Documentation::CppReference::get_url(const std::string symbol) noexcept {
4+
std::string Documentation::CppReference::get_url(const std::string &symbol) noexcept {
55
// Copied from http://upload.cppreference.com/mwiki/images/d/df/html_book_20170409.zip/reference/cppreference-export-ns0,4,8,10.xml
66
// Using raw string instead of map to reduce compile time
77
const static std::string symbol_urls = R"(size_t c/types/size_t

src/documentation_cppreference.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
namespace Documentation {
55
class CppReference {
66
public:
7-
static std::string get_url(const std::string symbol) noexcept;
7+
static std::string get_url(const std::string &symbol) noexcept;
88
};
99
}

src/menu.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ const Glib::ustring menu_xml= R"RAW(<interface>
477477
</interface>
478478
)RAW";
479479

480-
void Menu::add_action(const std::string &name, std::function<void()> action) {
480+
void Menu::add_action(const std::string &name, const std::function<void()> &action) {
481481
auto g_application=g_application_get_default();
482482
auto gio_application=Glib::wrap(g_application, true);
483483
auto application=Glib::RefPtr<Gtk::Application>::cast_static(gio_application);

src/menu.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class Menu {
1212
return singleton;
1313
}
1414

15-
void add_action(const std::string &name, std::function<void()> action);
15+
void add_action(const std::string &name, const std::function<void()> &action);
1616
std::unordered_map<std::string, Glib::RefPtr<Gio::SimpleAction> > actions;
1717
void set_keys();
1818

0 commit comments

Comments
 (0)