aboutsummaryrefslogtreecommitdiffstats
path: root/src/libs/3rdparty/syntax-highlighting/src/lib/dynamicregexpcache_p.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/libs/3rdparty/syntax-highlighting/src/lib/dynamicregexpcache_p.h')
-rw-r--r--src/libs/3rdparty/syntax-highlighting/src/lib/dynamicregexpcache_p.h39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/libs/3rdparty/syntax-highlighting/src/lib/dynamicregexpcache_p.h b/src/libs/3rdparty/syntax-highlighting/src/lib/dynamicregexpcache_p.h
new file mode 100644
index 0000000000..dcef97a841
--- /dev/null
+++ b/src/libs/3rdparty/syntax-highlighting/src/lib/dynamicregexpcache_p.h
@@ -0,0 +1,39 @@
+/*
+ SPDX-FileCopyrightText: 2023 Jonathan Poelen <jonathan.poelen+kde@gmail.com>
+
+ SPDX-License-Identifier: MIT
+*/
+
+#ifndef KSYNTAXHIGHLIGHTING_DYNAMICREGEXPCACHE_P_H
+#define KSYNTAXHIGHLIGHTING_DYNAMICREGEXPCACHE_P_H
+
+#include <QCache>
+#include <QRegularExpression>
+#include <QString>
+
+#include <utility>
+
+namespace KSyntaxHighlighting
+{
+
+class DynamicRegexpCache
+{
+public:
+ const QRegularExpression &compileRegexp(QString &&pattern, QRegularExpression::PatternOptions patternOptions)
+ {
+ const auto key = std::pair{std::move(pattern), patternOptions};
+ if (const auto regexp = m_cache.object(key)) {
+ return *regexp;
+ }
+ auto regexp = new QRegularExpression(key.first, patternOptions);
+ m_cache.insert(key, regexp);
+ return *regexp;
+ }
+
+private:
+ QCache<std::pair<QString, QRegularExpression::PatternOptions>, QRegularExpression> m_cache;
+};
+
+}
+
+#endif