Skip to content

Commit f1075a3

Browse files
committed
[FileSystem] Avoid <stack> include (NFC)
The standard pattern in LLVM is to directly use vectors for stacks, without an additional std::stack wrapper to rename some methods.
1 parent bc82793 commit f1075a3

File tree

3 files changed

+17
-15
lines changed

3 files changed

+17
-15
lines changed

llvm/include/llvm/Support/FileSystem.h

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
#include <cstdint>
4141
#include <ctime>
4242
#include <memory>
43-
#include <stack>
4443
#include <string>
4544
#include <system_error>
4645
#include <vector>
@@ -1471,7 +1470,7 @@ namespace detail {
14711470

14721471
/// Keeps state for the recursive_directory_iterator.
14731472
struct RecDirIterState {
1474-
std::stack<directory_iterator, std::vector<directory_iterator>> Stack;
1473+
std::vector<directory_iterator> Stack;
14751474
uint16_t Level = 0;
14761475
bool HasNoPushRequest = false;
14771476
};
@@ -1490,8 +1489,8 @@ class recursive_directory_iterator {
14901489
bool follow_symlinks = true)
14911490
: State(std::make_shared<detail::RecDirIterState>()),
14921491
Follow(follow_symlinks) {
1493-
State->Stack.push(directory_iterator(path, ec, Follow));
1494-
if (State->Stack.top() == directory_iterator())
1492+
State->Stack.push_back(directory_iterator(path, ec, Follow));
1493+
if (State->Stack.back() == directory_iterator())
14951494
State.reset();
14961495
}
14971496

@@ -1502,27 +1501,28 @@ class recursive_directory_iterator {
15021501
if (State->HasNoPushRequest)
15031502
State->HasNoPushRequest = false;
15041503
else {
1505-
file_type type = State->Stack.top()->type();
1504+
file_type type = State->Stack.back()->type();
15061505
if (type == file_type::symlink_file && Follow) {
15071506
// Resolve the symlink: is it a directory to recurse into?
1508-
ErrorOr<basic_file_status> status = State->Stack.top()->status();
1507+
ErrorOr<basic_file_status> status = State->Stack.back()->status();
15091508
if (status)
15101509
type = status->type();
15111510
// Otherwise broken symlink, and we'll continue.
15121511
}
15131512
if (type == file_type::directory_file) {
1514-
State->Stack.push(directory_iterator(*State->Stack.top(), ec, Follow));
1515-
if (State->Stack.top() != end_itr) {
1513+
State->Stack.push_back(
1514+
directory_iterator(*State->Stack.back(), ec, Follow));
1515+
if (State->Stack.back() != end_itr) {
15161516
++State->Level;
15171517
return *this;
15181518
}
1519-
State->Stack.pop();
1519+
State->Stack.pop_back();
15201520
}
15211521
}
15221522

15231523
while (!State->Stack.empty()
1524-
&& State->Stack.top().increment(ec) == end_itr) {
1525-
State->Stack.pop();
1524+
&& State->Stack.back().increment(ec) == end_itr) {
1525+
State->Stack.pop_back();
15261526
--State->Level;
15271527
}
15281528

@@ -1533,8 +1533,8 @@ class recursive_directory_iterator {
15331533
return *this;
15341534
}
15351535

1536-
const directory_entry &operator*() const { return *State->Stack.top(); }
1537-
const directory_entry *operator->() const { return &*State->Stack.top(); }
1536+
const directory_entry &operator*() const { return *State->Stack.back(); }
1537+
const directory_entry *operator->() const { return &*State->Stack.back(); }
15381538

15391539
// observers
15401540
/// Gets the current level. Starting path is at level 0.
@@ -1554,10 +1554,10 @@ class recursive_directory_iterator {
15541554
do {
15551555
if (ec)
15561556
report_fatal_error("Error incrementing directory iterator.");
1557-
State->Stack.pop();
1557+
State->Stack.pop_back();
15581558
--State->Level;
15591559
} while (!State->Stack.empty()
1560-
&& State->Stack.top().increment(ec) == end_itr);
1560+
&& State->Stack.back().increment(ec) == end_itr);
15611561

15621562
// Check if we are done. If so, create an end iterator.
15631563
if (State->Stack.empty())

llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757

5858
#include <cstdint>
5959
#include <optional>
60+
#include <stack>
6061

6162
#define DEBUG_TYPE "openmp-ir-builder"
6263

llvm/lib/Transforms/IPO/MemProfContextDisambiguation.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
#include "llvm/Support/raw_ostream.h"
4545
#include "llvm/Transforms/IPO.h"
4646
#include "llvm/Transforms/Utils/Cloning.h"
47+
#include <deque>
4748
#include <sstream>
4849
#include <unordered_map>
4950
#include <vector>

0 commit comments

Comments
 (0)