Coverage Report

Created: 2022-01-25 06:29

/Users/buildslave/jenkins/workspace/coverage/llvm-project/lldb/source/Core/FileSpecList.cpp
Line
Count
Source (jump to first uncovered line)
1
//===-- FileSpecList.cpp --------------------------------------------------===//
2
//
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
// See https://llvm.org/LICENSE.txt for license information.
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
//
7
//===----------------------------------------------------------------------===//
8
9
#include "lldb/Core/FileSpecList.h"
10
11
#include "lldb/Utility/ConstString.h"
12
#include "lldb/Utility/Stream.h"
13
14
#include <utility>
15
16
#include <cstdint>
17
18
using namespace lldb_private;
19
using namespace std;
20
21
634k
FileSpecList::FileSpecList() : m_files() {}
22
23
1.20M
FileSpecList::~FileSpecList() = default;
24
25
// Append the "file_spec" to the end of the file spec list.
26
1.13M
void FileSpecList::Append(const FileSpec &file_spec) {
27
1.13M
  m_files.push_back(file_spec);
28
1.13M
}
29
30
// Only append the "file_spec" if this list doesn't already contain it.
31
//
32
// Returns true if "file_spec" was added, false if this list already contained
33
// a copy of "file_spec".
34
1.69M
bool FileSpecList::AppendIfUnique(const FileSpec &file_spec) {
35
1.69M
  collection::iterator end = m_files.end();
36
1.69M
  if (find(m_files.begin(), end, file_spec) == end) {
37
655k
    m_files.push_back(file_spec);
38
655k
    return true;
39
655k
  }
40
1.04M
  return false;
41
1.69M
}
42
43
// Clears the file list.
44
41.3k
void FileSpecList::Clear() { m_files.clear(); }
45
46
// Dumps the file list to the supplied stream pointer "s".
47
0
void FileSpecList::Dump(Stream *s, const char *separator_cstr) const {
48
0
  collection::const_iterator pos, end = m_files.end();
49
0
  for (pos = m_files.begin(); pos != end; ++pos) {
50
0
    pos->Dump(s->AsRawOstream());
51
0
    if (separator_cstr && ((pos + 1) != end))
52
0
      s->PutCString(separator_cstr);
53
0
  }
54
0
}
55
56
// Find the index of the file in the file spec list that matches "file_spec"
57
// starting "start_idx" entries into the file spec list.
58
//
59
// Returns the valid index of the file that matches "file_spec" if it is found,
60
// else std::numeric_limits<uint32_t>::max() is returned.
61
size_t FileSpecList::FindFileIndex(size_t start_idx, const FileSpec &file_spec,
62
428k
                                   bool full) const {
63
428k
  const size_t num_files = m_files.size();
64
65
  // When looking for files, we will compare only the filename if the FILE_SPEC
66
  // argument is empty
67
428k
  bool compare_filename_only = file_spec.GetDirectory().IsEmpty();
68
69
1.06M
  for (size_t idx = start_idx; idx < num_files; 
++idx631k
) {
70
648k
    if (compare_filename_only) {
71
69.5k
      if (ConstString::Equals(
72
69.5k
              m_files[idx].GetFilename(), file_spec.GetFilename(),
73
69.5k
              file_spec.IsCaseSensitive() || 
m_files[idx].IsCaseSensitive()0
))
74
1.53k
        return idx;
75
578k
    } else {
76
578k
      if (FileSpec::Equal(m_files[idx], file_spec, full))
77
14.9k
        return idx;
78
578k
    }
79
648k
  }
80
81
  // We didn't find the file, return an invalid index
82
412k
  return UINT32_MAX;
83
428k
}
84
85
// Returns the FileSpec object at index "idx". If "idx" is out of range, then
86
// an empty FileSpec object will be returned.
87
593k
const FileSpec &FileSpecList::GetFileSpecAtIndex(size_t idx) const {
88
593k
  if (idx < m_files.size())
89
593k
    return m_files[idx];
90
13
  static FileSpec g_empty_file_spec;
91
13
  return g_empty_file_spec;
92
593k
}
93
94
0
const FileSpec *FileSpecList::GetFileSpecPointerAtIndex(size_t idx) const {
95
0
  if (idx < m_files.size())
96
0
    return &m_files[idx];
97
0
  return nullptr;
98
0
}
99
100
// Return the size in bytes that this object takes in memory. This returns the
101
// size in bytes of this object's member variables and any FileSpec objects its
102
// member variables contain, the result doesn't not include the string values
103
// for the directories any filenames as those are in shared string pools.
104
0
size_t FileSpecList::MemorySize() const {
105
0
  size_t mem_size = sizeof(FileSpecList);
106
0
  collection::const_iterator pos, end = m_files.end();
107
0
  for (pos = m_files.begin(); pos != end; ++pos) {
108
0
    mem_size += pos->MemorySize();
109
0
  }
110
111
0
  return mem_size;
112
0
}
113
114
// Return the number of files in the file spec list.
115
1.24M
size_t FileSpecList::GetSize() const { return m_files.size(); }
116
117
size_t FileSpecList::GetFilesMatchingPartialPath(const char *path,
118
                                                 bool dir_okay,
119
0
                                                 FileSpecList &matches) {
120
0
  return 0;
121
0
}