mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-09-19 22:40:26 +00:00
redoParagraph: avoid extra cache accesses
To this end, CoordCacheBase::add returns true when a change was made. This uses the return value of std::unordered_map::insert.
This commit is contained in:
parent
608929a857
commit
45dce93af7
@ -75,9 +75,21 @@ public:
|
||||
data_[thing].pos = Point(x, y);
|
||||
}
|
||||
|
||||
void add(T const * thing, Dimension const & dim)
|
||||
// this returns true if a change is done
|
||||
bool add(T const * thing, Dimension const & dim)
|
||||
{
|
||||
data_[thing].dim = dim;
|
||||
Geometry g;
|
||||
g.dim = dim;
|
||||
auto const result = data_.insert(std::make_pair(thing, g));
|
||||
// did a new entry get inserted?
|
||||
if (result.second)
|
||||
return true;
|
||||
// otherwise, if the existing value is different, update it
|
||||
else if (result.first->second.dim != dim) {
|
||||
result.first->second.dim = dim;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
Geometry & geometry(T const * thing)
|
||||
|
@ -605,10 +605,7 @@ bool TextMetrics::redoParagraph(pit_type const pit, bool const align_rows)
|
||||
*/
|
||||
extrawidths[e.inset] = mi.extrawidth;
|
||||
|
||||
if (!insetCache.has(e.inset) || insetCache.dim(e.inset) != dim) {
|
||||
insetCache.add(e.inset, dim);
|
||||
changed = true;
|
||||
}
|
||||
changed |= insetCache.add(e.inset, dim);
|
||||
}
|
||||
|
||||
// Transform the paragraph into a single row containing all the elements.
|
||||
|
Loading…
Reference in New Issue
Block a user