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.
This commit is contained in:
Jay Berkenbilt 2022-08-07 14:23:05 -04:00
parent 32e30a3af2
commit da71dc6f37
2 changed files with 12 additions and 2 deletions

2
TODO
View File

@ -10,6 +10,8 @@ Before Release:
* Cache environment variables * Cache environment variables
* Remove coverage cases for things that are heavily exercised or are * Remove coverage cases for things that are heavily exercised or are
in critical paths in critical paths
* Make ./performance_check usable by other people by having published
files to use for testing.
* Evaluate issues tagged with `next` * Evaluate issues tagged with `next`
* Stay on top of https://github.com/pikepdf/pikepdf/pull/315 * Stay on top of https://github.com/pikepdf/pikepdf/pull/315

View File

@ -2,6 +2,7 @@
#include <qpdf/QUtil.hh> #include <qpdf/QUtil.hh>
#include <set> #include <set>
#include <map>
#include <stdio.h> #include <stdio.h>
static bool static bool
@ -14,12 +15,19 @@ tc_active(char const* const scope)
void void
QTC::TC(char const* const scope, char const* const ccase, int n) 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; return;
} }
static std::set<std::pair<std::string, int>> cache;
std::string filename; std::string filename;
#ifdef _WIN32 #ifdef _WIN32
# define TC_ENV "TC_WIN_FILENAME" # define TC_ENV "TC_WIN_FILENAME"