Commit da71dc6f37c69bdf708f1f9876e63ff348ae2296

Authored by Jay Berkenbilt
1 parent 32e30a3a

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.
Showing 2 changed files with 12 additions and 2 deletions
@@ -10,6 +10,8 @@ Before Release: @@ -10,6 +10,8 @@ Before Release:
10 * Cache environment variables 10 * Cache environment variables
11 * Remove coverage cases for things that are heavily exercised or are 11 * Remove coverage cases for things that are heavily exercised or are
12 in critical paths 12 in critical paths
  13 +* Make ./performance_check usable by other people by having published
  14 + files to use for testing.
13 * Evaluate issues tagged with `next` 15 * Evaluate issues tagged with `next`
14 * Stay on top of https://github.com/pikepdf/pikepdf/pull/315 16 * Stay on top of https://github.com/pikepdf/pikepdf/pull/315
15 17
libqpdf/QTC.cc
@@ -2,6 +2,7 @@ @@ -2,6 +2,7 @@
2 2
3 #include <qpdf/QUtil.hh> 3 #include <qpdf/QUtil.hh>
4 #include <set> 4 #include <set>
  5 +#include <map>
5 #include <stdio.h> 6 #include <stdio.h>
6 7
7 static bool 8 static bool
@@ -14,12 +15,19 @@ tc_active(char const* const scope) @@ -14,12 +15,19 @@ tc_active(char const* const scope)
14 void 15 void
15 QTC::TC(char const* const scope, char const* const ccase, int n) 16 QTC::TC(char const* const scope, char const* const ccase, int n)
16 { 17 {
17 - static std::set<std::pair<std::string, int>> cache; 18 + static std::map<std::string, bool> active;
  19 + auto is_active = active.find(scope);
  20 + if (is_active == active.end()) {
  21 + active[scope] = tc_active(scope);
  22 + is_active = active.find(scope);
  23 + }
18 24
19 - if (!tc_active(scope)) { 25 + if (!is_active->second) {
20 return; 26 return;
21 } 27 }
22 28
  29 + static std::set<std::pair<std::string, int>> cache;
  30 +
23 std::string filename; 31 std::string filename;
24 #ifdef _WIN32 32 #ifdef _WIN32
25 # define TC_ENV "TC_WIN_FILENAME" 33 # define TC_ENV "TC_WIN_FILENAME"