>From 1a54c60e67d21b01a4468a91eb2a69b808c1acda Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 7 Oct 2015 15:18:23 +0200 Subject: [PATCH] Only initialize the unique paths emit_ledger really needs Small optimization: don't call unique_filepath() needlessly for the paths that are not going to be used because the corresponding emission type is not requested anyhow in ledger_emitter constructor. Only construct the paths that we're really going to need, if any. --- emit_ledger.cpp | 19 +++++++++++++++---- emit_ledger.hpp | 14 ++++++++------ 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/emit_ledger.cpp b/emit_ledger.cpp index 760b7b1..f5dac3a 100644 --- a/emit_ledger.cpp +++ b/emit_ledger.cpp @@ -57,13 +57,24 @@ ,mcenum_emission emission ) :case_filepath_ (case_filepath) - ,tsv_ext_ (configurable_settings::instance().spreadsheet_file_extension()) - ,case_filepath_spreadsheet_ (unique_filepath(case_filepath, tsv_ext_)) - ,case_filepath_group_roster_ (unique_filepath(case_filepath, ".roster" + tsv_ext_)) - ,case_filepath_group_quote_ (unique_filepath(case_filepath, ".quote.pdf" )) ,emission_ (emission) { LMI_ASSERT(!case_filepath_.empty()); + + std::string const& tsv_ext = configurable_settings::instance().spreadsheet_file_extension(); + + if(emission_ & mce_emit_spreadsheet) + { + case_filepath_spreadsheet_ = unique_filepath(case_filepath, tsv_ext); + } + if(emission_ & mce_emit_group_roster) + { + case_filepath_group_roster_ = unique_filepath(case_filepath, ".roster" + tsv_ext); + } + if(emission_ & mce_emit_group_quote) + { + case_filepath_group_quote_ = unique_filepath(case_filepath, ".quote.pdf"); + } } ledger_emitter::~ledger_emitter() diff --git a/emit_ledger.hpp b/emit_ledger.hpp index d3555a2..421c41a 100644 --- a/emit_ledger.hpp +++ b/emit_ledger.hpp @@ -55,12 +55,14 @@ class LMI_SO ledger_emitter double finish (); private: - fs::path const& case_filepath_; - std::string const tsv_ext_; - fs::path const case_filepath_spreadsheet_; - fs::path const case_filepath_group_roster_; - fs::path const case_filepath_group_quote_; - mcenum_emission emission_; + fs::path const& case_filepath_; + mcenum_emission emission_; + + // These file paths are only initialized when they are used, i.e. when + // emission_ contains the corresponding bit mask. + fs::path case_filepath_spreadsheet_; + fs::path case_filepath_group_roster_; + fs::path case_filepath_group_quote_; // Used only if emission includes mce_emit_group_quote; empty otherwise. boost::shared_ptr group_quote_gen_; -- 2.5.1