ClangFormat: Add caching of current style

Previously, ClangFormat was getting the style for a file
every time styleForFile was called, which could cause
unnecessary delays and impact performance. This commit
adds caching of the current style with a timeout of 1s,
so that ClangFormat can quickly access the cached style
instead of recalculating it each time.

Change-Id: I33c114d51d6ce1acd0b6d9d2a28e2b6712e149dd
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
Artem Sokolovskii
2023-05-12 11:57:26 +02:00
parent 375db16ac4
commit 74f77f6407
3 changed files with 46 additions and 7 deletions

View File

@@ -31,7 +31,7 @@ using namespace Utils;
namespace ClangFormat {
clang::format::FormatStyle qtcStyle()
clang::format::FormatStyle calculateQtcStyle()
{
clang::format::FormatStyle style = getLLVMStyle();
style.Language = FormatStyle::LK_Cpp;
@@ -179,6 +179,12 @@ clang::format::FormatStyle qtcStyle()
return style;
}
clang::format::FormatStyle qtcStyle()
{
static clang::format::FormatStyle style = calculateQtcStyle();
return style;
}
QString projectUniqueId(ProjectExplorer::Project *project)
{
if (!project)