Skip to content

Commit 635d0fe

Browse files
committed
OrcLib: LocationSet: keep the discovering volume order
1 parent 4ed2bbd commit 635d0fe

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

src/OrcLib/LocationSet.cpp

+19-7
Original file line numberDiff line numberDiff line change
@@ -155,16 +155,28 @@ void GetShadowCopyLocations(const std::vector<Location::Ptr>& locations, ShadowC
155155
}
156156
}
157157

158+
// Use this function and a vector instead of std::set to keep original ordering
159+
void UniquePushBack(const Orc::Location::Ptr& location, std::vector<Orc::Location::Ptr>& items)
160+
{
161+
auto it = std::find_if(
162+
std::cbegin(items), std::cend(items), [&location](const auto& item) { return item.get() == location.get(); });
163+
164+
if (it == std::cend(items))
165+
{
166+
items.push_back(location);
167+
}
168+
};
169+
158170
void FilterLocations(
159171
const std::vector<Location::Ptr>& locations,
160172
const LocationSet::ShadowFilters& filters,
161-
std::set<Location::Ptr>& output)
173+
std::vector<Location::Ptr>& output)
162174
{
163175
if (filters.empty())
164176
{
165177
for (const auto& loc : locations)
166178
{
167-
output.insert(loc);
179+
UniquePushBack(loc, output);
168180
}
169181

170182
return;
@@ -179,17 +191,17 @@ void FilterLocations(
179191

180192
if (shadows.newest && filters.find(L"newest") != std::cend(filters))
181193
{
182-
output.insert(shadows.newest);
194+
UniquePushBack(shadows.newest, output);
183195
}
184196

185197
if (shadows.mid && filters.find(L"mid") != std::cend(filters))
186198
{
187-
output.insert(shadows.mid);
199+
UniquePushBack(shadows.mid, output);
188200
}
189201

190202
if (shadows.oldest && filters.find(L"oldest") != std::cend(filters))
191203
{
192-
output.insert(shadows.oldest);
204+
UniquePushBack(shadows.oldest, output);
193205
}
194206

195207
for (const auto& filter : filters)
@@ -200,7 +212,7 @@ void FilterLocations(
200212
auto it = shadows.guids.find(*guid);
201213
if (it != std::cend(shadows.guids))
202214
{
203-
output.insert(it->second);
215+
UniquePushBack(it->second, output);
204216
}
205217
}
206218
}
@@ -2299,7 +2311,7 @@ HRESULT LocationSet::AltitudeLocations(
22992311
shadowCopiesLocations.push_back(std::move(vssLoc));
23002312
}
23012313

2302-
std::set<Location::Ptr> shadowsSelection;
2314+
std::vector<Location::Ptr> shadowsSelection;
23032315
::FilterLocations(shadowCopiesLocations, shadowFilters, shadowsSelection);
23042316

23052317
for (const auto& loc : shadowsSelection)

0 commit comments

Comments
 (0)