summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/clangd/ClangdUnitStore.cpp
blob: bc2479d669e240993fb82233fbd5a67fd965bdaf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
//===--- ClangdUnitStore.cpp - A ClangdUnits container -----------*-C++-*-===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

#include "ClangdUnitStore.h"
#include "llvm/Support/Path.h"
#include <algorithm>

using namespace clang::clangd;
using namespace clang;

std::shared_ptr<CppFile> CppFileCollection::removeIfPresent(PathRef File) {
  std::lock_guard<std::mutex> Lock(Mutex);

  auto It = OpenedFiles.find(File);
  if (It == OpenedFiles.end())
    return nullptr;

  std::shared_ptr<CppFile> Result = It->second;
  OpenedFiles.erase(It);
  return Result;
}
std::vector<std::pair<Path, std::size_t>>
CppFileCollection::getUsedBytesPerFile() const {
  std::lock_guard<std::mutex> Lock(Mutex);
  std::vector<std::pair<Path, std::size_t>> Result;
  Result.reserve(OpenedFiles.size());
  for (auto &&PathAndFile : OpenedFiles)
    Result.push_back(
        {PathAndFile.first().str(), PathAndFile.second->getUsedBytes()});
  return Result;
}
OpenPOWER on IntegriCloud