diff --git a/src/filesystem.cc b/src/filesystem.cc index c433dae0..dad07ddd 100644 --- a/src/filesystem.cc +++ b/src/filesystem.cc @@ -31,7 +31,8 @@ void getFilesInFolder(std::string folder, bool recursive, bool dir_prefix, curr.pop_back(); for (sys::fs::directory_iterator i(folder1, ec, false), e; i != e && !ec; i.increment(ec)) { - std::string path = i->path(), filename = sys::path::filename(path); + std::string path = i->path(); + std::string filename(sys::path::filename(path)); if ((filename[0] == '.' && filename != ".ccls") || sys::fs::status(path, status, false)) continue; diff --git a/src/indexer.cc b/src/indexer.cc index a281e54b..014a7e8b 100644 --- a/src/indexer.cc +++ b/src/indexer.cc @@ -504,7 +504,7 @@ public: llvm::raw_svector_ostream os(str); d->print(os, getDefaultPolicy()); - std::string name = os.str(); + std::string name(str.data(), str.size()); simplifyAnonymous(name); // Remove \n in DeclPrinter.cpp "{\n" + if(!TerseOutput)something + "}" for (std::string::size_type i = 0;;) { diff --git a/src/main.cc b/src/main.cc index 93f9d3b7..eb18d26c 100644 --- a/src/main.cc +++ b/src/main.cc @@ -134,7 +134,7 @@ int main(int argc, char **argv) { if (opt_index.size()) { SmallString<256> root(opt_index); sys::fs::make_absolute(root); - pipeline::standalone(root.str()); + pipeline::standalone(std::string(root.data(), root.size())); } else { // The thread that reads from stdin and dispatchs commands to the main // thread. diff --git a/src/pipeline.cc b/src/pipeline.cc index 107ca4a1..4773c69b 100644 --- a/src/pipeline.cc +++ b/src/pipeline.cc @@ -113,7 +113,7 @@ bool cacheInvalid(VFS *vfs, IndexFile *prev, const std::string &path, } // For inferred files, allow -o a a.cc -> -o b b.cc - std::string stem = sys::path::stem(path); + StringRef stem = sys::path::stem(path); int changed = -1, size = std::min(prev->args.size(), args.size()); for (int i = 0; i < size; i++) if (strcmp(prev->args[i], args[i]) && sys::path::stem(args[i]) != stem) { diff --git a/src/platform.hh b/src/platform.hh index 5fa7cfe7..ecb6326d 100644 --- a/src/platform.hh +++ b/src/platform.hh @@ -1,14 +1,14 @@ -// Copyright 2017-2018 ccls Authors +// Copyright 2017-2020 ccls Authors // SPDX-License-Identifier: Apache-2.0 #pragma once +#include + #include -#include -#include namespace ccls { -std::string normalizePath(const std::string &path); +std::string normalizePath(llvm::StringRef path); // Free any unused memory and return it to the system. void freeUnusedMemory(); diff --git a/src/platform_posix.cc b/src/platform_posix.cc index 6fd04995..5a937c65 100644 --- a/src/platform_posix.cc +++ b/src/platform_posix.cc @@ -40,7 +40,7 @@ namespace pipeline { void threadEnter(); } -std::string normalizePath(const std::string &path) { +std::string normalizePath(llvm::StringRef path) { llvm::SmallString<256> p(path); llvm::sys::path::remove_dots(p, true); return {p.data(), p.size()}; diff --git a/src/platform_win.cc b/src/platform_win.cc index 9fa28e3b..4cafb3d7 100644 --- a/src/platform_win.cc +++ b/src/platform_win.cc @@ -19,17 +19,12 @@ #include namespace ccls { -std::string normalizePath(const std::string &path) { - DWORD retval = 0; +std::string normalizePath(llvm::StringRef path) { TCHAR buffer[MAX_PATH] = TEXT(""); TCHAR **lpp_part = {NULL}; - std::string result; - retval = GetFullPathName(path.c_str(), MAX_PATH, buffer, lpp_part); - // fail, return original - if (retval == 0) - result = path; - else + std::string result(path); + if (GetFullPathName(result.c_str(), MAX_PATH, buffer, lpp_part) != 0) result = buffer; std::replace(result.begin(), result.end(), '\\', '/'); diff --git a/src/project.cc b/src/project.cc index 54a56f23..0761f291 100644 --- a/src/project.cc +++ b/src/project.cc @@ -222,7 +222,7 @@ readCompilerArgumentsFromFile(const std::string &path) { return {}; std::vector args; for (line_iterator i(*mbOrErr.get(), true, '#'), e; i != e; ++i) { - std::string line = *i; + std::string line(*i); doPathMapping(line); args.push_back(intern(line)); } @@ -632,7 +632,7 @@ void Project::index(WorkingFiles *wfiles, RequestId id) { void Project::indexRelated(const std::string &path) { auto &gi = g_config->index; GroupMatch match(gi.whitelist, gi.blacklist); - std::string stem = sys::path::stem(path); + StringRef stem = sys::path::stem(path); std::vector args, extra_args; for (const std::string &arg : g_config->clang.extraArgs) extra_args.push_back(intern(arg)); diff --git a/src/sema_manager.cc b/src/sema_manager.cc index 8bc8db83..d97875e6 100644 --- a/src/sema_manager.cc +++ b/src/sema_manager.cc @@ -623,9 +623,10 @@ void *diagnosticMain(void *manager_) { for (const Note &n : d.notes) { SmallString<256> str(n.file); llvm::sys::path::remove_dots(str, true); - Location loc{DocumentUri::fromPath(str.str()), - lsRange{{n.range.start.line, n.range.start.column}, - {n.range.end.line, n.range.end.column}}}; + Location loc{ + DocumentUri::fromPath(std::string(str.data(), str.size())), + lsRange{{n.range.start.line, n.range.start.column}, + {n.range.end.line, n.range.end.column}}}; ls_diag.relatedInformation.push_back({loc, n.message}); } } else { diff --git a/src/serializer.cc b/src/serializer.cc index 6d878ac4..99cea067 100644 --- a/src/serializer.cc +++ b/src/serializer.cc @@ -217,7 +217,7 @@ void reflect(JsonWriter &vis, IndexInclude &v) { reflectMemberStart(vis); REFLECT_MEMBER(line); if (gTestOutputMode) { - std::string basename = llvm::sys::path::filename(v.resolved_path); + std::string basename(llvm::sys::path::filename(v.resolved_path)); if (v.resolved_path[0] != '&') basename = "&" + basename; REFLECT_MEMBER2("resolved_path", basename);