Guard debug code in commodity.cc, so it will build optimized.

This commit is contained in:
John Wiegley 2009-01-23 19:50:35 -04:00
parent 784ec4b787
commit c49f05a15a

View file

@ -142,8 +142,10 @@ optional<price_point_t>
#endif #endif
if (prices.size() == 0) { if (prices.size() == 0) {
#if defined(DEBUG_ON)
DEBUG_INDENT("commodity.prices", indent); DEBUG_INDENT("commodity.prices", indent);
DEBUG("commodity.prices", " there are no prices in this history"); DEBUG("commodity.prices", " there are no prices in this history");
#endif
return none; return none;
} }
@ -152,8 +154,10 @@ optional<price_point_t>
point.when = (*r).first; point.when = (*r).first;
point.price = (*r).second; point.price = (*r).second;
found = true; found = true;
#if defined(DEBUG_ON)
DEBUG_INDENT("commodity.prices", indent); DEBUG_INDENT("commodity.prices", indent);
DEBUG("commodity.prices", " using most recent price"); DEBUG("commodity.prices", " using most recent price");
#endif
} else { } else {
history_map::const_iterator i = prices.lower_bound(*moment); history_map::const_iterator i = prices.lower_bound(*moment);
if (i == prices.end()) { if (i == prices.end()) {
@ -161,8 +165,10 @@ optional<price_point_t>
point.when = (*r).first; point.when = (*r).first;
point.price = (*r).second; point.price = (*r).second;
found = true; found = true;
#if defined(DEBUG_ON)
DEBUG_INDENT("commodity.prices", indent); DEBUG_INDENT("commodity.prices", indent);
DEBUG("commodity.prices", " using last price"); DEBUG("commodity.prices", " using last price");
#endif
} else { } else {
point.when = (*i).first; point.when = (*i).first;
if (*moment < point.when) { if (*moment < point.when) {
@ -176,8 +182,10 @@ optional<price_point_t>
point.price = (*i).second; point.price = (*i).second;
found = true; found = true;
} }
#if defined(DEBUG_ON)
DEBUG_INDENT("commodity.prices", indent); DEBUG_INDENT("commodity.prices", indent);
DEBUG("commodity.prices", " using found price"); DEBUG("commodity.prices", " using found price");
#endif
} }
} }
@ -192,24 +200,32 @@ optional<price_point_t>
#endif #endif
if (! found) { if (! found) {
#if defined(DEBUG_ON)
DEBUG_INDENT("commodity.prices", indent); DEBUG_INDENT("commodity.prices", indent);
DEBUG("commodity.prices", " could not find a price"); DEBUG("commodity.prices", " could not find a price");
#endif
return none; return none;
} }
else if (moment && point.when > *moment) { else if (moment && point.when > *moment) {
#if defined(DEBUG_ON)
DEBUG_INDENT("commodity.prices", indent); DEBUG_INDENT("commodity.prices", indent);
DEBUG("commodity.prices", " price is too young "); DEBUG("commodity.prices", " price is too young ");
#endif
return none; return none;
} }
else if (oldest && point.when < *oldest) { else if (oldest && point.when < *oldest) {
#if defined(DEBUG_ON)
DEBUG_INDENT("commodity.prices", indent); DEBUG_INDENT("commodity.prices", indent);
DEBUG("commodity.prices", " price is too old "); DEBUG("commodity.prices", " price is too old ");
#endif
return none; return none;
} }
else { else {
#if defined(DEBUG_ON)
DEBUG_INDENT("commodity.prices", indent); DEBUG_INDENT("commodity.prices", indent);
DEBUG("commodity.prices", DEBUG("commodity.prices",
" returning price: " << point.when << ", " << point.price); " returning price: " << point.when << ", " << point.price);
#endif
return point; return point;
} }
} }
@ -263,59 +279,83 @@ optional<price_point_t>
if (comm == source) if (comm == source)
continue; continue;
#if defined(DEBUG_ON)
DEBUG_INDENT("commodity.prices", indent + 1); DEBUG_INDENT("commodity.prices", indent + 1);
DEBUG("commodity.prices", DEBUG("commodity.prices",
" searching for price via commodity '" << comm << "'"); " searching for price via commodity '" << comm << "'");
#endif
point = hist.second.find_price(source, commodity, moment, limit, indent + 2); point = hist.second.find_price(source, commodity, moment, limit
#if defined(DEBUG_ON)
, indent + 2
#endif
);
assert(! point || point->price.commodity() == comm); assert(! point || point->price.commodity() == comm);
if (point) { if (point) {
optional<price_point_t> xlat; optional<price_point_t> xlat;
if (commodity && comm != *commodity) { if (commodity && comm != *commodity) {
#if defined(DEBUG_ON)
DEBUG_INDENT("commodity.prices", indent + 1); DEBUG_INDENT("commodity.prices", indent + 1);
DEBUG("commodity.prices", " looking for translation price"); DEBUG("commodity.prices", " looking for translation price");
#endif
xlat = comm.find_price(commodity, moment, limit, indent + 2); xlat = comm.find_price(commodity, moment, limit
#if defined(DEBUG_ON)
, indent + 2
#endif
);
if (xlat) { if (xlat) {
#if defined(DEBUG_ON)
DEBUG_INDENT("commodity.prices", indent + 1); DEBUG_INDENT("commodity.prices", indent + 1);
DEBUG("commodity.prices", " found translated price " DEBUG("commodity.prices", " found translated price "
<< xlat->price << " from " << xlat->when); << xlat->price << " from " << xlat->when);
#endif
point->price = xlat->price * point->price; point->price = xlat->price * point->price;
if (xlat->when < point->when) { if (xlat->when < point->when) {
point->when = xlat->when; point->when = xlat->when;
#if defined(DEBUG_ON)
DEBUG_INDENT("commodity.prices", indent + 1); DEBUG_INDENT("commodity.prices", indent + 1);
DEBUG("commodity.prices", DEBUG("commodity.prices",
" adjusting date of result back to " << point->when); " adjusting date of result back to " << point->when);
#endif
} }
} else { } else {
#if defined(DEBUG_ON)
DEBUG_INDENT("commodity.prices", indent + 1); DEBUG_INDENT("commodity.prices", indent + 1);
DEBUG("commodity.prices", " saw no translated price there"); DEBUG("commodity.prices", " saw no translated price there");
#endif
continue; continue;
} }
} }
assert(! commodity || point->price.commodity() == *commodity); assert(! commodity || point->price.commodity() == *commodity);
#if defined(DEBUG_ON)
DEBUG_INDENT("commodity.prices", indent + 1); DEBUG_INDENT("commodity.prices", indent + 1);
DEBUG("commodity.prices", DEBUG("commodity.prices",
" saw a price there: " << point->price << " from " << point->when); " saw a price there: " << point->price << " from " << point->when);
#endif
if (! limit || point->when > *limit) { if (! limit || point->when > *limit) {
limit = point->when; limit = point->when;
best = *point; best = *point;
found = true; found = true;
} }
} else { } else {
#if defined(DEBUG_ON)
DEBUG_INDENT("commodity.prices", indent + 1); DEBUG_INDENT("commodity.prices", indent + 1);
DEBUG("commodity.prices", " saw no price there"); DEBUG("commodity.prices", " saw no price there");
#endif
} }
} }
if (found) { if (found) {
#if defined(DEBUG_ON)
DEBUG_INDENT("commodity.prices", indent); DEBUG_INDENT("commodity.prices", indent);
DEBUG("commodity.prices", DEBUG("commodity.prices",
" found price " << best.price << " from " << best.when); " found price " << best.price << " from " << best.when);
#endif
return best; return best;
} }
return none; return none;