@@ -70,8 +70,6 @@ class LazyMappedFileRegion {
70
70
// / and/or update callers not to rely on this.
71
71
StringRef getPath () const { return Path; }
72
72
73
- char *data () const { return Map.data (); }
74
-
75
73
// / Resize to at least \p MinSize.
76
74
// /
77
75
// / Errors if \p MinSize is bigger than \a capacity() or if the operation
@@ -86,10 +84,18 @@ class LazyMappedFileRegion {
86
84
// / Size allocated on disk.
87
85
size_t size () const { return CachedSize; }
88
86
87
+ #ifdef _WIN32
88
+ char *data () const { return VM; }
89
+ // / Size of the underlying \a mapped_file_region. This cannot be extended.
90
+ size_t capacity () const { return MaxSize; }
91
+ explicit operator bool () const { return VM; }
92
+ #else
93
+ char *data () const { return Map.data (); }
89
94
// / Size of the underlying \a mapped_file_region. This cannot be extended.
90
95
size_t capacity () const { return Map.size (); }
91
-
92
96
explicit operator bool () const { return bool (Map); }
97
+ #endif
98
+
93
99
94
100
~LazyMappedFileRegion () { destroyImpl (); }
95
101
@@ -106,27 +112,34 @@ class LazyMappedFileRegion {
106
112
107
113
private:
108
114
Error extendSizeImpl (uint64_t MinSize);
109
- void destroyImpl () {
110
- if (FD) {
111
- sys::fs::closeFile (*FD);
112
- FD = None;
113
- }
114
- }
115
+ void destroyImpl ();
115
116
void moveImpl (LazyMappedFileRegion &RHS) {
116
117
Path = std::move (RHS.Path );
117
118
FD = std::move (RHS.FD );
118
- RHS.FD = None;
119
+ RHS.FD = std::nullopt;
120
+ #ifdef _WIN32
121
+ VM = RHS.VM ;
122
+ MaxSize = RHS.MaxSize ;
123
+ MappedRegions = RHS.MappedRegions ;
124
+ #else
119
125
Map = std::move (RHS.Map );
126
+ assert (!RHS.Map &&
127
+ " Expected std::optional(std::optional&&) to clear RHS.Map" );
128
+ #endif
120
129
CachedSize = RHS.CachedSize .load ();
121
130
RHS.CachedSize = 0 ;
122
131
MaxSizeIncrement = RHS.MaxSizeIncrement ;
123
-
124
- assert (!RHS.Map && " Expected Optional(Optional&&) to clear RHS.Map" );
125
132
}
126
133
127
134
std::string Path;
128
- Optional<sys::fs::file_t > FD;
135
+ std::optional<int > FD;
136
+ #ifdef _WIN32
137
+ char *VM = nullptr ;
138
+ uint64_t MaxSize = 0 ;
139
+ std::vector<void *> MappedRegions;
140
+ #else
129
141
sys::fs::mapped_file_region Map;
142
+ #endif
130
143
std::atomic<uint64_t > CachedSize;
131
144
std::mutex Mutex;
132
145
uint64_t MaxSizeIncrement = 0 ;
0 commit comments