Optimizations

This commit is contained in:
John Wiegley 2012-02-27 11:52:27 -06:00
parent 5532a1a8b7
commit 3ed09fc85b
2 changed files with 62 additions and 55 deletions

View file

@ -136,21 +136,23 @@ account_t * journal_t::register_account(const string& name, post_t * post,
} }
} }
if (! result->has_flags(ACCOUNT_KNOWN)) { if (checking_style == CHECK_WARNING || checking_style == CHECK_ERROR) {
if (! post) { if (! result->has_flags(ACCOUNT_KNOWN)) {
if (force_checking) if (! post) {
fixed_accounts = true; if (force_checking)
result->add_flags(ACCOUNT_KNOWN); fixed_accounts = true;
} result->add_flags(ACCOUNT_KNOWN);
else if (! fixed_accounts && post->_state != item_t::UNCLEARED) { }
result->add_flags(ACCOUNT_KNOWN); else if (! fixed_accounts && post->_state != item_t::UNCLEARED) {
} result->add_flags(ACCOUNT_KNOWN);
else if (checking_style == CHECK_WARNING) { }
warning_(_("%1Unknown account '%2'") << location else if (checking_style == CHECK_WARNING) {
<< result->fullname()); warning_(_("%1Unknown account '%2'") << location
} << result->fullname());
else if (checking_style == CHECK_ERROR) { }
throw_(parse_error, _("Unknown account '%1'") << result->fullname()); else if (checking_style == CHECK_ERROR) {
throw_(parse_error, _("Unknown account '%1'") << result->fullname());
}
} }
} }
@ -197,24 +199,26 @@ void journal_t::register_commodity(commodity_t& comm,
variant<int, xact_t *, post_t *> context, variant<int, xact_t *, post_t *> context,
const string& location) const string& location)
{ {
if (! comm.has_flags(COMMODITY_KNOWN)) { if (checking_style == CHECK_WARNING || checking_style == CHECK_ERROR) {
if (context.which() == 0) { if (! comm.has_flags(COMMODITY_KNOWN)) {
if (force_checking) if (context.which() == 0) {
fixed_commodities = true; if (force_checking)
comm.add_flags(COMMODITY_KNOWN); fixed_commodities = true;
} comm.add_flags(COMMODITY_KNOWN);
else if (! fixed_commodities && }
((context.which() == 1 && else if (! fixed_commodities &&
boost::get<xact_t *>(context)->_state != item_t::UNCLEARED) || ((context.which() == 1 &&
(context.which() == 2 && boost::get<xact_t *>(context)->_state != item_t::UNCLEARED) ||
boost::get<post_t *>(context)->_state != item_t::UNCLEARED))) { (context.which() == 2 &&
comm.add_flags(COMMODITY_KNOWN); boost::get<post_t *>(context)->_state != item_t::UNCLEARED))) {
} comm.add_flags(COMMODITY_KNOWN);
else if (checking_style == CHECK_WARNING) { }
warning_(_("%1Unknown commodity '%2'") << location << comm); else if (checking_style == CHECK_WARNING) {
} warning_(_("%1Unknown commodity '%2'") << location << comm);
else if (checking_style == CHECK_ERROR) { }
throw_(parse_error, _("Unknown commodity '%1'") << comm); else if (checking_style == CHECK_ERROR) {
throw_(parse_error, _("Unknown commodity '%1'") << comm);
}
} }
} }
} }
@ -254,26 +258,28 @@ void journal_t::register_metadata(const string& key, const value_t& value,
variant<int, xact_t *, post_t *> context, variant<int, xact_t *, post_t *> context,
const string& location) const string& location)
{ {
std::set<string>::iterator i = known_tags.find(key); if (checking_style == CHECK_WARNING || checking_style == CHECK_ERROR) {
std::set<string>::iterator i = known_tags.find(key);
if (i == known_tags.end()) { if (i == known_tags.end()) {
if (context.which() == 0) { if (context.which() == 0) {
if (force_checking) if (force_checking)
fixed_metadata = true; fixed_metadata = true;
known_tags.insert(key); known_tags.insert(key);
} }
else if (! fixed_metadata && else if (! fixed_metadata &&
((context.which() == 1 && ((context.which() == 1 &&
boost::get<xact_t *>(context)->_state != item_t::UNCLEARED) || boost::get<xact_t *>(context)->_state != item_t::UNCLEARED) ||
(context.which() == 2 && (context.which() == 2 &&
boost::get<post_t *>(context)->_state != item_t::UNCLEARED))) { boost::get<post_t *>(context)->_state != item_t::UNCLEARED))) {
known_tags.insert(key); known_tags.insert(key);
} }
else if (checking_style == CHECK_WARNING) { else if (checking_style == CHECK_WARNING) {
warning_(_("%1Unknown metadata tag '%2'") << location << key); warning_(_("%1Unknown metadata tag '%2'") << location << key);
} }
else if (checking_style == CHECK_ERROR) { else if (checking_style == CHECK_ERROR) {
throw_(parse_error, _("Unknown metadata tag '%1'") << key); throw_(parse_error, _("Unknown metadata tag '%1'") << key);
}
} }
} }

View file

@ -565,7 +565,6 @@ bool xact_t::valid() const
} }
namespace { namespace {
bool post_pred(expr_t::ptr_op_t op, post_t& post) bool post_pred(expr_t::ptr_op_t op, post_t& post)
{ {
switch (op->kind) { switch (op->kind) {
@ -582,6 +581,9 @@ namespace {
else else
break; break;
case expr_t::op_t::O_EQ:
return post_pred(op->left(), post) == post_pred(op->right(), post);
case expr_t::op_t::O_NOT: case expr_t::op_t::O_NOT:
return ! post_pred(op->left(), post); return ! post_pred(op->left(), post);
@ -604,8 +606,7 @@ namespace {
throw_(calc_error, _("Unhandled operator")); throw_(calc_error, _("Unhandled operator"));
return false; return false;
} }
}
} // unnamed namespace
void auto_xact_t::extend_xact(xact_base_t& xact) void auto_xact_t::extend_xact(xact_base_t& xact)
{ {