[llvm] 75d7180 - [VirtualFileSystem] Use map to stabilize iteration order
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 19 22:25:45 PDT 2023
Author: Fangrui Song
Date: 2023-07-19T22:25:40-07:00
New Revision: 75d71800aa384ee58663d892c325572f5588df2a
URL: https://github.com/llvm/llvm-project/commit/75d71800aa384ee58663d892c325572f5588df2a
DIFF: https://github.com/llvm/llvm-project/commit/75d71800aa384ee58663d892c325572f5588df2a.diff
LOG: [VirtualFileSystem] Use map to stabilize iteration order
StringMap iteration order is not guaranteed to be deterministic
(https://llvm.org/docs/ProgrammersManual.html#llvm-adt-stringmap-h).
Tested by `TEST_F(InMemoryFileSystemTest, DirectoryIteration)`.
Added:
Modified:
llvm/lib/Support/VirtualFileSystem.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Support/VirtualFileSystem.cpp b/llvm/lib/Support/VirtualFileSystem.cpp
index acb0df2b15f58c..9c1c9905fa2921 100644
--- a/llvm/lib/Support/VirtualFileSystem.cpp
+++ b/llvm/lib/Support/VirtualFileSystem.cpp
@@ -43,6 +43,7 @@
#include <cstdint>
#include <iterator>
#include <limits>
+#include <map>
#include <memory>
#include <optional>
#include <string>
@@ -725,7 +726,7 @@ class InMemoryFileAdaptor : public File {
class InMemoryDirectory : public InMemoryNode {
Status Stat;
- llvm::StringMap<std::unique_ptr<InMemoryNode>> Entries;
+ std::map<std::string, std::unique_ptr<InMemoryNode>> Entries;
public:
InMemoryDirectory(Status Stat)
@@ -741,7 +742,7 @@ class InMemoryDirectory : public InMemoryNode {
UniqueID getUniqueID() const { return Stat.getUniqueID(); }
InMemoryNode *getChild(StringRef Name) const {
- auto I = Entries.find(Name);
+ auto I = Entries.find(Name.str());
if (I != Entries.end())
return I->second.get();
return nullptr;
More information about the llvm-commits
mailing list