summaryrefslogtreecommitdiff
path: root/src/or/config.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2014-09-23 08:46:35 -0400
committerNick Mathewson <nickm@torproject.org>2014-09-29 09:05:11 -0400
commit4903ab1caaf0b2631e6091b58b31eaff0c9f8424 (patch)
treebfd51b9ea637076a90f331e02c2367a18ee23ac2 /src/or/config.c
parent8527a2996675d9502551ccdd4224036a45aae47b (diff)
downloadtor-4903ab1caaf0b2631e6091b58b31eaff0c9f8424.tar.gz
tor-4903ab1caaf0b2631e6091b58b31eaff0c9f8424.zip
Avoid frequent strcmp() calls for AccountingRule
Generally, we don't like to parse the same thing over and over; it's best IMO to do it once at the start of the code.
Diffstat (limited to 'src/or/config.c')
-rw-r--r--src/or/config.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/src/or/config.c b/src/or/config.c
index c7c61549ae..8035afbc79 100644
--- a/src/or/config.c
+++ b/src/or/config.c
@@ -126,7 +126,7 @@ static config_abbrev_t option_abbrevs_[] = {
*/
static config_var_t option_vars_[] = {
V(AccountingMax, MEMUNIT, "0 bytes"),
- V(AccountingRule, STRING, "max"),
+ VAR("AccountingRule", STRING, AccountingRule_option, "max"),
V(AccountingStart, STRING, NULL),
V(Address, STRING, NULL),
V(AllowDotExit, BOOL, "0"),
@@ -3109,9 +3109,15 @@ options_validate(or_options_t *old_options, or_options_t *options,
"risky: they will all turn off at the same time, which may "
"alert observers that they are being run by the same party.");
}
- if (options->AccountingRule &&
- strcmp(options->AccountingRule, "sum") != 0 &&
- strcmp(options->AccountingRule, "max") != 0)
+ }
+
+ options->AccountingRule = ACCT_MAX;
+ if (options->AccountingRule_option) {
+ if (!strcmp(options->AccountingRule_option, "sum"))
+ options->AccountingRule = ACCT_SUM;
+ else if (!strcmp(options->AccountingRule_option, "max"))
+ options->AccountingRule = ACCT_MAX;
+ else
REJECT("AccountingRule must be 'sum' or 'max'");
}