From 4070113ef0fef840a0fdd5104c38fb23cd0008eb Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Thu, 11 Apr 2013 21:44:30 +0900 Subject: [PATCH] Save options directly specified for download in --save-session This change makes --save-session save only options specified for download, more specifically, options in command-line, -i file and via RPC. The other options from conf file and default values are not saved. This will drastically decrease the size of session file. --- src/Option.cc | 34 +++++++++++++++++++++++++++++++--- src/Option.h | 29 ++++++++++++++++++++++------- src/SessionSerializer.cc | 2 +- src/main.cc | 18 ++++++++++-------- src/option_processing.cc | 40 +++++++++++++++++++++++++--------------- test/OptionTest.cc | 30 ++++++++++++++++++++++++++++++ 6 files changed, 119 insertions(+), 34 deletions(-) diff --git a/src/Option.cc b/src/Option.cc index 652c9233..f86060d7 100644 --- a/src/Option.cc +++ b/src/Option.cc @@ -51,7 +51,8 @@ Option::~Option() {} Option::Option(const Option& option) : table_(option.table_), - use_(option.use_) + use_(option.use_), + parent_(option.parent_) {} Option& Option::operator=(const Option& option) @@ -59,6 +60,7 @@ Option& Option::operator=(const Option& option) if(this != &option) { table_ = option.table_; use_ = option.use_; + parent_ = option.parent_; } return *this; } @@ -85,18 +87,34 @@ void Option::put(const Pref* pref, const std::string& value) { } bool Option::defined(const Pref* pref) const +{ + return bitfield::test(use_, use_.size()*8, pref->i) || + (parent_ && parent_->defined(pref)); +} + +bool Option::definedLocal(const Pref* pref) const { return bitfield::test(use_, use_.size()*8, pref->i); } bool Option::blank(const Pref* pref) const { - return !defined(pref) || table_[pref->i].empty(); + if(bitfield::test(use_, use_.size()*8, pref->i)) { + return table_[pref->i].empty(); + } else { + return !parent_ || parent_->blank(pref); + } } const std::string& Option::get(const Pref* pref) const { - return table_[pref->i]; + if(bitfield::test(use_, use_.size()*8, pref->i)) { + return table_[pref->i]; + } else if(parent_) { + return parent_->get(pref); + } else { + return A2STR::NIL; + } } int32_t Option::getAsInt(const Pref* pref) const { @@ -153,4 +171,14 @@ void Option::merge(const Option& option) } } +void Option::setParent(const SharedHandle