]> git.lyx.org Git - features.git/commit
Improve (modestly) the performance of font metrics caches
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Fri, 24 Sep 2021 14:57:05 +0000 (16:57 +0200)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Fri, 24 Sep 2021 15:12:15 +0000 (17:12 +0200)
commit6bbd88accfb76248d00346f308ba1f67f186e094
treecf85babd3f065c639278d7a832f77c9c1149ac12
parent9ae002b69f5ae140448b71f8b41ce8797f328468
Improve (modestly) the performance of font metrics caches

This fixes two performance issues and improves the performance of
TextMetrics::redoParagraph by 15% in a workload that uses the cache a
lot. The difference will be much less when the cache is not used much.

1/ repetion of the hash code computation

The code
  if (cache.contains(key))
   result = cache[key]:
is not efficient, since qHash(key) has to be computed twice.
To fix this a new Cache::object_str() method is added, which allows
  if (auto * obj = cache.object(key))
   result = *obj;

2/ code of has code computation

Instead of using a verbose string that is complicated to build as
key, new key structs BreakAtKey and TextLayoutKey are introduced,
along with the relevant qHash() implementation.
src/frontends/qt/GuiFontMetrics.cpp
src/frontends/qt/GuiFontMetrics.h
src/support/Cache.h