aboutsummaryrefslogtreecommitdiffstats
path: root/libqpdf/QTC.cc
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2022-08-07 20:23:05 +0200
committerJay Berkenbilt <ejb@ql.org>2022-08-07 20:23:05 +0200
commitda71dc6f37c69bdf708f1f9876e63ff348ae2296 (patch)
tree74c0505a6053e799758c501211b53c6f3d4b113d /libqpdf/QTC.cc
parent32e30a3af2f3198e1522a42bdde8faa1cd1a88df (diff)
downloadqpdf-da71dc6f37c69bdf708f1f9876e63ff348ae2296.tar.zst
QTC: cache get_env results for improved performance
It turns out that QUtil::get_env is particularly expensive on Windows if there is a large environment. This may be true on other platforms as well.
Diffstat (limited to 'libqpdf/QTC.cc')
-rw-r--r--libqpdf/QTC.cc12
1 files changed, 10 insertions, 2 deletions
diff --git a/libqpdf/QTC.cc b/libqpdf/QTC.cc
index d27bfa8b..21d240ba 100644
--- a/libqpdf/QTC.cc
+++ b/libqpdf/QTC.cc
@@ -2,6 +2,7 @@
#include <qpdf/QUtil.hh>
#include <set>
+#include <map>
#include <stdio.h>
static bool
@@ -14,12 +15,19 @@ tc_active(char const* const scope)
void
QTC::TC(char const* const scope, char const* const ccase, int n)
{
- static std::set<std::pair<std::string, int>> cache;
+ static std::map<std::string, bool> active;
+ auto is_active = active.find(scope);
+ if (is_active == active.end()) {
+ active[scope] = tc_active(scope);
+ is_active = active.find(scope);
+ }
- if (!tc_active(scope)) {
+ if (!is_active->second) {
return;
}
+ static std::set<std::pair<std::string, int>> cache;
+
std::string filename;
#ifdef _WIN32
# define TC_ENV "TC_WIN_FILENAME"