mirror of
https://github.com/MaskRay/ccls.git
synced 2025-06-07 16:54:54 +00:00
clang-tidy performance fixes
This commit is contained in:
parent
4711fd36a3
commit
85b31f7c1e
@ -63,7 +63,7 @@ void DocumentUri::setPath(const std::string &path) {
|
|||||||
// file:///c%3A/Users/jacob/Desktop/superindex/indexer/full_tests
|
// file:///c%3A/Users/jacob/Desktop/superindex/indexer/full_tests
|
||||||
raw_uri = path;
|
raw_uri = path;
|
||||||
|
|
||||||
size_t index = raw_uri.find(":");
|
size_t index = raw_uri.find(':');
|
||||||
if (index == 1) { // widows drive letters must always be 1 char
|
if (index == 1) { // widows drive letters must always be 1 char
|
||||||
raw_uri.replace(raw_uri.begin() + index, raw_uri.begin() + index + 1,
|
raw_uri.replace(raw_uri.begin() + index, raw_uri.begin() + index + 1,
|
||||||
"%3A");
|
"%3A");
|
||||||
|
@ -121,9 +121,8 @@ void ReplyOnce::replyLocationLink(std::vector<LocationLink> &result) {
|
|||||||
if (g_config->client.linkSupport) {
|
if (g_config->client.linkSupport) {
|
||||||
(*this)(result);
|
(*this)(result);
|
||||||
} else {
|
} else {
|
||||||
std::vector<Location> result1;
|
std::vector<Location> result1{std::make_move_iterator(result.begin()),
|
||||||
for (auto &loc : result)
|
std::make_move_iterator(result.end())};
|
||||||
result1.emplace_back(std::move(loc));
|
|
||||||
(*this)(result1);
|
(*this)(result1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -32,8 +32,9 @@ struct WorkingFile;
|
|||||||
struct WorkingFiles;
|
struct WorkingFiles;
|
||||||
|
|
||||||
namespace pipeline {
|
namespace pipeline {
|
||||||
void reply(RequestId id, const std::function<void(JsonWriter &)> &fn);
|
void reply(const RequestId &id, const std::function<void(JsonWriter &)> &fn);
|
||||||
void replyError(RequestId id, const std::function<void(JsonWriter &)> &fn);
|
void replyError(const RequestId &id,
|
||||||
|
const std::function<void(JsonWriter &)> &fn);
|
||||||
} // namespace pipeline
|
} // namespace pipeline
|
||||||
|
|
||||||
struct CodeActionParam {
|
struct CodeActionParam {
|
||||||
|
@ -101,7 +101,7 @@ void MessageHandler::workspace_didChangeWorkspaceFolders(
|
|||||||
if (folder == real)
|
if (folder == real)
|
||||||
real.clear();
|
real.clear();
|
||||||
LOG_S(INFO) << "add workspace folder " << wf.name << ": "
|
LOG_S(INFO) << "add workspace folder " << wf.name << ": "
|
||||||
<< (real.empty() ? folder : folder + " -> " + real);
|
<< (real.empty() ? folder : (folder + " -> ").append(real));
|
||||||
workspaceFolders.emplace_back();
|
workspaceFolders.emplace_back();
|
||||||
auto it = workspaceFolders.end() - 1;
|
auto it = workspaceFolders.end() - 1;
|
||||||
for (; it != workspaceFolders.begin() && folder < it[-1].first; --it)
|
for (; it != workspaceFolders.begin() && folder < it[-1].first; --it)
|
||||||
|
@ -616,13 +616,13 @@ void mainLoop() {
|
|||||||
|
|
||||||
SemaManager manager(
|
SemaManager manager(
|
||||||
&project, &wfiles,
|
&project, &wfiles,
|
||||||
[&](std::string path, std::vector<Diagnostic> diagnostics) {
|
[&](const std::string &path, std::vector<Diagnostic> diagnostics) {
|
||||||
PublishDiagnosticParam params;
|
PublishDiagnosticParam params;
|
||||||
params.uri = DocumentUri::fromPath(path);
|
params.uri = DocumentUri::fromPath(path);
|
||||||
params.diagnostics = diagnostics;
|
params.diagnostics = std::move(diagnostics);
|
||||||
notify("textDocument/publishDiagnostics", params);
|
notify("textDocument/publishDiagnostics", params);
|
||||||
},
|
},
|
||||||
[](RequestId id) {
|
[](const RequestId &id) {
|
||||||
if (id.valid()) {
|
if (id.valid()) {
|
||||||
ResponseError err;
|
ResponseError err;
|
||||||
err.code = ErrorCode::InternalError;
|
err.code = ErrorCode::InternalError;
|
||||||
@ -717,8 +717,9 @@ void standalone(const std::string &root) {
|
|||||||
WorkingFiles wfiles;
|
WorkingFiles wfiles;
|
||||||
VFS vfs;
|
VFS vfs;
|
||||||
SemaManager manager(
|
SemaManager manager(
|
||||||
nullptr, nullptr, [&](std::string, std::vector<Diagnostic>) {},
|
nullptr, nullptr,
|
||||||
[](RequestId id) {});
|
[&](const std::string &, const std::vector<Diagnostic> &) {},
|
||||||
|
[](const RequestId &id) {});
|
||||||
IncludeComplete complete(&project);
|
IncludeComplete complete(&project);
|
||||||
|
|
||||||
MessageHandler handler;
|
MessageHandler handler;
|
||||||
@ -756,7 +757,7 @@ void standalone(const std::string &root) {
|
|||||||
void index(const std::string &path, const std::vector<const char *> &args,
|
void index(const std::string &path, const std::vector<const char *> &args,
|
||||||
IndexMode mode, bool must_exist, RequestId id) {
|
IndexMode mode, bool must_exist, RequestId id) {
|
||||||
pending_index_requests++;
|
pending_index_requests++;
|
||||||
index_request->pushBack({path, args, mode, must_exist, id},
|
index_request->pushBack({path, args, mode, must_exist, std::move(id)},
|
||||||
mode != IndexMode::Background);
|
mode != IndexMode::Background);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -800,7 +801,7 @@ void notifyOrRequest(const char *method, bool request,
|
|||||||
for_stdout->pushBack(output.GetString());
|
for_stdout->pushBack(output.GetString());
|
||||||
}
|
}
|
||||||
|
|
||||||
static void reply(RequestId id, const char *key,
|
static void reply(const RequestId &id, const char *key,
|
||||||
const std::function<void(JsonWriter &)> &fn) {
|
const std::function<void(JsonWriter &)> &fn) {
|
||||||
rapidjson::StringBuffer output;
|
rapidjson::StringBuffer output;
|
||||||
rapidjson::Writer<rapidjson::StringBuffer> w(output);
|
rapidjson::Writer<rapidjson::StringBuffer> w(output);
|
||||||
@ -828,11 +829,12 @@ static void reply(RequestId id, const char *key,
|
|||||||
for_stdout->pushBack(output.GetString());
|
for_stdout->pushBack(output.GetString());
|
||||||
}
|
}
|
||||||
|
|
||||||
void reply(RequestId id, const std::function<void(JsonWriter &)> &fn) {
|
void reply(const RequestId &id, const std::function<void(JsonWriter &)> &fn) {
|
||||||
reply(id, "result", fn);
|
reply(id, "result", fn);
|
||||||
}
|
}
|
||||||
|
|
||||||
void replyError(RequestId id, const std::function<void(JsonWriter &)> &fn) {
|
void replyError(const RequestId &id,
|
||||||
|
const std::function<void(JsonWriter &)> &fn) {
|
||||||
reply(id, "error", fn);
|
reply(id, "error", fn);
|
||||||
}
|
}
|
||||||
} // namespace pipeline
|
} // namespace pipeline
|
||||||
|
@ -65,10 +65,11 @@ template <typename T> void request(const char *method, T &result) {
|
|||||||
notifyOrRequest(method, true, [&](JsonWriter &w) { reflect(w, result); });
|
notifyOrRequest(method, true, [&](JsonWriter &w) { reflect(w, result); });
|
||||||
}
|
}
|
||||||
|
|
||||||
void reply(RequestId id, const std::function<void(JsonWriter &)> &fn);
|
void reply(const RequestId &id, const std::function<void(JsonWriter &)> &fn);
|
||||||
|
|
||||||
void replyError(RequestId id, const std::function<void(JsonWriter &)> &fn);
|
void replyError(const RequestId &id,
|
||||||
template <typename T> void replyError(RequestId id, T &result) {
|
const std::function<void(JsonWriter &)> &fn);
|
||||||
|
template <typename T> void replyError(const RequestId &id, T &result) {
|
||||||
replyError(id, [&](JsonWriter &w) { reflect(w, result); });
|
replyError(id, [&](JsonWriter &w) { reflect(w, result); });
|
||||||
}
|
}
|
||||||
} // namespace pipeline
|
} // namespace pipeline
|
||||||
|
@ -249,7 +249,7 @@ bool appendToCDB(const std::vector<const char *> &args) {
|
|||||||
return args.size() && StringRef("%compile_commands.json") == args[0];
|
return args.size() && StringRef("%compile_commands.json") == args[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<const char *> getFallback(const std::string path) {
|
std::vector<const char *> getFallback(const std::string &path) {
|
||||||
std::vector<const char *> argv{"clang"};
|
std::vector<const char *> argv{"clang"};
|
||||||
if (sys::path::extension(path) == ".h")
|
if (sys::path::extension(path) == ".h")
|
||||||
argv.push_back("-xobjective-c++-header");
|
argv.push_back("-xobjective-c++-header");
|
||||||
@ -607,7 +607,7 @@ Project::Entry Project::findEntry(const std::string &path, bool can_redirect,
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Project::index(WorkingFiles *wfiles, RequestId id) {
|
void Project::index(WorkingFiles *wfiles, const RequestId &id) {
|
||||||
auto &gi = g_config->index;
|
auto &gi = g_config->index;
|
||||||
GroupMatch match(gi.whitelist, gi.blacklist),
|
GroupMatch match(gi.whitelist, gi.blacklist),
|
||||||
match_i(gi.initialWhitelist, gi.initialBlacklist);
|
match_i(gi.initialWhitelist, gi.initialBlacklist);
|
||||||
|
@ -76,7 +76,7 @@ struct Project {
|
|||||||
void setArgsForFile(const std::vector<const char *> &args,
|
void setArgsForFile(const std::vector<const char *> &args,
|
||||||
const std::string &path);
|
const std::string &path);
|
||||||
|
|
||||||
void index(WorkingFiles *wfiles, RequestId id);
|
void index(WorkingFiles *wfiles, const RequestId &id);
|
||||||
void indexRelated(const std::string &path);
|
void indexRelated(const std::string &path);
|
||||||
};
|
};
|
||||||
} // namespace ccls
|
} // namespace ccls
|
||||||
|
@ -231,7 +231,7 @@ class StoreDiags : public DiagnosticConsumer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
StoreDiags(std::string path) : path(path) {}
|
StoreDiags(std::string path) : path{std::move(path)} {}
|
||||||
std::vector<Diag> take() { return std::move(output); }
|
std::vector<Diag> take() { return std::move(output); }
|
||||||
bool isConcerned(const SourceManager &sm, SourceLocation l) {
|
bool isConcerned(const SourceManager &sm, SourceLocation l) {
|
||||||
FileID fid = sm.getFileID(l);
|
FileID fid = sm.getFileID(l);
|
||||||
@ -683,8 +683,10 @@ std::shared_ptr<PreambleData> Session::getPreamble() {
|
|||||||
|
|
||||||
SemaManager::SemaManager(Project *project, WorkingFiles *wfiles,
|
SemaManager::SemaManager(Project *project, WorkingFiles *wfiles,
|
||||||
OnDiagnostic on_diagnostic, OnDropped on_dropped)
|
OnDiagnostic on_diagnostic, OnDropped on_dropped)
|
||||||
: project_(project), wfiles(wfiles), on_diagnostic_(on_diagnostic),
|
: project_(project), wfiles(wfiles),
|
||||||
on_dropped_(on_dropped), pch(std::make_shared<PCHContainerOperations>()) {
|
on_diagnostic_(std::move(on_diagnostic)),
|
||||||
|
on_dropped_(std::move(on_dropped)),
|
||||||
|
pch(std::make_shared<PCHContainerOperations>()) {
|
||||||
spawnThread(ccls::preambleMain, this);
|
spawnThread(ccls::preambleMain, this);
|
||||||
spawnThread(ccls::completionMain, this);
|
spawnThread(ccls::completionMain, this);
|
||||||
spawnThread(ccls::diagnosticMain, this);
|
spawnThread(ccls::diagnosticMain, this);
|
||||||
|
@ -35,7 +35,7 @@ bool gTestOutputMode = false;
|
|||||||
|
|
||||||
namespace ccls {
|
namespace ccls {
|
||||||
|
|
||||||
void JsonReader::iterArray(std::function<void()> fn) {
|
void JsonReader::iterArray(const llvm::function_ref<void()> fn) {
|
||||||
if (!m->IsArray())
|
if (!m->IsArray())
|
||||||
throw std::invalid_argument("array");
|
throw std::invalid_argument("array");
|
||||||
// Use "0" to indicate any element for now.
|
// Use "0" to indicate any element for now.
|
||||||
@ -48,7 +48,7 @@ void JsonReader::iterArray(std::function<void()> fn) {
|
|||||||
}
|
}
|
||||||
path_.pop_back();
|
path_.pop_back();
|
||||||
}
|
}
|
||||||
void JsonReader::member(const char *name, std::function<void()> fn) {
|
void JsonReader::member(const char *name, const llvm::function_ref<void()> fn) {
|
||||||
path_.push_back(name);
|
path_.push_back(name);
|
||||||
auto it = m->FindMember(name);
|
auto it = m->FindMember(name);
|
||||||
if (it != m->MemberEnd()) {
|
if (it != m->MemberEnd()) {
|
||||||
|
@ -17,6 +17,7 @@ limitations under the License.
|
|||||||
|
|
||||||
#include "utils.hh"
|
#include "utils.hh"
|
||||||
|
|
||||||
|
#include <llvm/ADT/STLExtras.h>
|
||||||
#include <llvm/Support/Compiler.h>
|
#include <llvm/Support/Compiler.h>
|
||||||
|
|
||||||
#include <macro_map.h>
|
#include <macro_map.h>
|
||||||
@ -48,8 +49,8 @@ struct JsonReader {
|
|||||||
JsonReader(rapidjson::Value *m) : m(m) {}
|
JsonReader(rapidjson::Value *m) : m(m) {}
|
||||||
void startObject() {}
|
void startObject() {}
|
||||||
void endObject() {}
|
void endObject() {}
|
||||||
void iterArray(std::function<void()> fn);
|
void iterArray(const llvm::function_ref<void()> fn);
|
||||||
void member(const char *name, std::function<void()> fn);
|
void member(const char *name, const llvm::function_ref<void()> fn);
|
||||||
bool isNull();
|
bool isNull();
|
||||||
std::string getString();
|
std::string getString();
|
||||||
std::string getPath() const;
|
std::string getPath() const;
|
||||||
|
@ -152,7 +152,7 @@ std::string realPath(const std::string &path) {
|
|||||||
bool normalizeFolder(std::string &path) {
|
bool normalizeFolder(std::string &path) {
|
||||||
for (auto &[root, real] : g_config->workspaceFolders)
|
for (auto &[root, real] : g_config->workspaceFolders)
|
||||||
if (real.size() && llvm::StringRef(path).startswith(real)) {
|
if (real.size() && llvm::StringRef(path).startswith(real)) {
|
||||||
path = root + path.substr(real.size());
|
path = root.append(path.substr(real.size()));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
Loading…
Reference in New Issue
Block a user