Small simplification/optimization of propagate_invalidation()
This commit is contained in:
parent
356c19fb33
commit
d0228ccad5
1 changed files with 13 additions and 19 deletions
|
@ -2334,28 +2334,22 @@ bool display::propagate_invalidation(const std::set<map_location>& locs)
|
||||||
if(invalidateAll_)
|
if(invalidateAll_)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
bool has_inval = false;
|
if(locs.size()<=1)
|
||||||
|
return false; // propagation never needed
|
||||||
|
|
||||||
|
// search the first hex invalidated (if any)
|
||||||
std::set<map_location>::const_iterator i = locs.begin();
|
std::set<map_location>::const_iterator i = locs.begin();
|
||||||
for(; i != locs.end(); ++i) {
|
for(; i != locs.end() && invalidated_.count(*i) == 0 ; ++i) {}
|
||||||
if (invalidated_.count(*i)) {
|
|
||||||
has_inval = true;
|
|
||||||
break; // 'i' will be used later
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// if no invalidation or one but nothing to propagate, return false
|
if (i == locs.end())
|
||||||
if (!has_inval || locs.size()<=1)
|
return false; // no invalidation, don't propagate
|
||||||
return false;
|
|
||||||
|
|
||||||
// propagate invalidation (but skip the already invalidated hex)
|
// propagate invalidation
|
||||||
bool res = false;
|
// 'i' is already in, but I suspect that splitting the range is bad
|
||||||
std::set<map_location>::const_iterator j = locs.begin();
|
// especially because locs are often adjacents
|
||||||
for(; j != locs.end(); ++j) {
|
size_t previous_size = invalidated_.size();
|
||||||
if(j != i)
|
invalidated_.insert(locs.begin(), locs.end());
|
||||||
res |= invalidated_.insert(*j).second;
|
return previous_size < invalidated_.size();
|
||||||
}
|
|
||||||
|
|
||||||
return res; // always true, but cleaner like that
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool display::invalidate_visible_locations_in_rect(const SDL_Rect& rect)
|
bool display::invalidate_visible_locations_in_rect(const SDL_Rect& rect)
|
||||||
|
|
Loading…
Add table
Reference in a new issue