summaryrefslogtreecommitdiff
path: root/src/context/context.cpp
diff options
context:
space:
mode:
authorMorgan Deters <mdeters@gmail.com>2010-07-04 18:36:22 +0000
committerMorgan Deters <mdeters@gmail.com>2010-07-04 18:36:22 +0000
commit693d70847d0ed753a4f035dd3c88eb32607e2081 (patch)
tree0076edc5a7fe9eaf6605bef8bb6804e6a48e4d85 /src/context/context.cpp
parent0679a64a1c1017d8ef0e26e40a476f2559e6bba3 (diff)
Considerably simplified the way output streams are used. This commit
should have no impact on production performance and speed up debug performance considerably, while making the code much cleaner. On some benchmarks, debug builds now run _much_ faster. We no longer have to sprinkle our code with things like: if(debugTagIsOn("context")) { Debug("context") << theContext << std::endl; } which we had to do to get around performance problems previously. Now just writing: Debug("context") << theContext << std::endl; does the same in production and debug builds. That is, if "context" debugging is off, theContext isn't converted to a string, nor is it output to a "/dev/null" ostream. I've confirmed this. In production builds, the whole statement inlines to nothing. I've confirmed this too. Also, "Debug" is no longer a #definition, so you can use it directly in production builds where you couldn't previously, e.g. if(Debug.isOn("paranoid:check_tableau")) { checkTableau(); } I'm leaving debugTagIsOn() for now, but marking it as deprecated.
Diffstat (limited to 'src/context/context.cpp')
-rw-r--r--src/context/context.cpp59
1 files changed, 23 insertions, 36 deletions
diff --git a/src/context/context.cpp b/src/context/context.cpp
index 994f644a7..0028aaad5 100644
--- a/src/context/context.cpp
+++ b/src/context/context.cpp
@@ -132,19 +132,15 @@ void Context::addNotifyObjPost(ContextNotifyObj* pCNO) {
void ContextObj::update() throw(AssertionException) {
- if(debugTagIsOn("context")) {
- Debug("context") << "before update(" << this << "):" << std::endl
- << *getContext() << std::endl;
- }
+ Debug("context") << "before update(" << this << "):" << std::endl
+ << *getContext() << std::endl;
// Call save() to save the information in the current object
ContextObj* pContextObjSaved = save(d_pScope->getCMM());
- if(debugTagIsOn("context")) {
- Debug("context") << "in update(" << this << ") with restore "
- << pContextObjSaved << ": waypoint 1" << std::endl
- << *getContext() << std::endl;
- }
+ Debug("context") << "in update(" << this << ") with restore "
+ << pContextObjSaved << ": waypoint 1" << std::endl
+ << *getContext() << std::endl;
// Check that base class data was saved
Assert( ( pContextObjSaved->d_pContextObjNext == d_pContextObjNext &&
@@ -173,11 +169,9 @@ void ContextObj::update() throw(AssertionException) {
Debug("context") << "in update(" << this
<< "): *prev() is now " << *prev() << std::endl;
- if(debugTagIsOn("context")) {
- Debug("context") << "in update(" << this << ") with restore "
- << pContextObjSaved << ": waypoint 3" << std::endl
- << *getContext() << std::endl;
- }
+ Debug("context") << "in update(" << this << ") with restore "
+ << pContextObjSaved << ": waypoint 3" << std::endl
+ << *getContext() << std::endl;
// Update Scope pointer to current top Scope
d_pScope = d_pScope->getContext()->getTopScope();
@@ -189,11 +183,9 @@ void ContextObj::update() throw(AssertionException) {
// Scope is popped.
d_pScope->addToChain(this);
- if(debugTagIsOn("context")) {
- Debug("context") << "after update(" << this << ") with restore "
- << pContextObjSaved << ":" << std::endl
- << *getContext() << std::endl;
- }
+ Debug("context") << "after update(" << this << ") with restore "
+ << pContextObjSaved << ":" << std::endl
+ << *getContext() << std::endl;
}
@@ -238,12 +230,11 @@ ContextObj* ContextObj::restoreAndContinue() throw(AssertionException) {
void ContextObj::destroy() throw(AssertionException) {
- if(debugTagIsOn("context")) {
- /* Context can be big and complicated, so we only want to process this output
- * if we're really going to use it. (Same goes below.) */
- Debug("context") << "before destroy " << this << " (level " << getLevel()
- << "):" << std::endl << *getContext() << std::endl;
- }
+ /* Context can be big and complicated, so we only want to process this output
+ * if we're really going to use it. (Same goes below.) */
+ Debug("context") << "before destroy " << this << " (level " << getLevel()
+ << "):" << std::endl << *getContext() << std::endl;
+
for(;;) {
// If valgrind reports invalid writes on the next few lines,
// here's a hint: make sure all classes derived from ContextObj in
@@ -256,18 +247,14 @@ void ContextObj::destroy() throw(AssertionException) {
if(d_pContextObjRestore == NULL) {
break;
}
- if(debugTagIsOn("context")) {
- Debug("context") << "in destroy " << this << ", restore object is "
- << d_pContextObjRestore << " at level "
- << d_pContextObjRestore->getLevel() << ":" << std::endl
- << *getContext() << std::endl;
- }
+ Debug("context") << "in destroy " << this << ", restore object is "
+ << d_pContextObjRestore << " at level "
+ << d_pContextObjRestore->getLevel() << ":" << std::endl
+ << *getContext() << std::endl;
restoreAndContinue();
}
- if(debugTagIsOn("context")) {
- Debug("context") << "after destroy " << this << ":" << std::endl
- << *getContext() << std::endl;
- }
+ Debug("context") << "after destroy " << this << ":" << std::endl
+ << *getContext() << std::endl;
}
@@ -318,7 +305,7 @@ ContextNotifyObj::~ContextNotifyObj() throw(AssertionException) {
std::ostream& operator<<(std::ostream& out,
const Context& context) throw(AssertionException) {
- const std::string separator(79, '-');
+ static const std::string separator(79, '-');
int level = context.d_scopeList.size() - 1;
typedef std::vector<Scope*>::const_reverse_iterator const_reverse_iterator;
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback