Skip to content

Commit

Permalink
avoid redundant dirty node settings
Browse files Browse the repository at this point in the history
  • Loading branch information
mariofusco committed Sep 22, 2016
1 parent 661f6f7 commit b08c1cc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 18 deletions.
15 changes: 6 additions & 9 deletions drools-core/src/main/java/org/drools/core/reteoo/BetaNode.java
Expand Up @@ -283,16 +283,16 @@ public void assertObject( final InternalFactHandle factHandle,

RightTuple rightTuple = createRightTuple( factHandle, this, pctx );

if ( memory.getStagedRightTuples().isEmpty() ) {
memory.setNodeDirtyWithoutNotify();
}
boolean stagedInsertWasEmpty = memory.getStagedRightTuples().addInsert(rightTuple);
if ( isLogTraceEnabled ) {
log.trace("BetaNode stagedInsertWasEmpty={}", stagedInsertWasEmpty );
}

boolean shouldFlush = isStreamMode();
if ( memory.getAndIncCounter() == 0 ) {
if ( stagedInsertWasEmpty ) {
memory.setNodeDirtyWithoutNotify();
}
shouldFlush = memory.linkNode(wm, !rightInputIsPassive) | shouldFlush;
} else if ( stagedInsertWasEmpty ) {
shouldFlush = memory.setNodeDirty( wm, !rightInputIsPassive ) | shouldFlush;
Expand Down Expand Up @@ -345,12 +345,12 @@ public void doDeleteRightTuple(final RightTuple rightTuple,
final BetaMemory memory) {
TupleSets<RightTuple> stagedRightTuples = memory.getStagedRightTuples();

if ( stagedRightTuples.isEmpty() ) {
memory.setNodeDirtyWithoutNotify();
}
boolean stagedDeleteWasEmpty = stagedRightTuples.addDelete(rightTuple);

if ( memory.getAndDecCounter() == 1 ) {
if ( stagedDeleteWasEmpty ) {
memory.setNodeDirtyWithoutNotify();
}
memory.unlinkNode(wm);
} else if ( stagedDeleteWasEmpty ) {
// nothing staged before, notify rule, so it can evaluate network
Expand All @@ -363,9 +363,6 @@ public void doUpdateRightTuple(final RightTuple rightTuple,
final BetaMemory memory) {
TupleSets<RightTuple> stagedRightTuples = memory.getStagedRightTuples();

if ( stagedRightTuples.isEmpty() ) {
memory.setNodeDirtyWithoutNotify();
}
boolean stagedUpdateWasEmpty = stagedRightTuples.addUpdate( rightTuple );

if ( stagedUpdateWasEmpty ) {
Expand Down
18 changes: 9 additions & 9 deletions drools-core/src/main/java/org/drools/core/reteoo/NotNode.java
Expand Up @@ -142,15 +142,15 @@ public void assertObject( final InternalFactHandle factHandle,

rightTuple.setPropagationContext(pctx);

// strangely we link here, this is actually just to force a network evaluation
// The assert is then processed and the rule unlinks then.
// This is because we need the first RightTuple to link with it's blocked
if ( memory.getStagedRightTuples().isEmpty() ) {
memory.setNodeDirtyWithoutNotify();
}
boolean stagedInsertWasEmpty = memory.getStagedRightTuples().addInsert( rightTuple );

if ( memory.getAndIncCounter() == 0 && isEmptyBetaConstraints() ) {
// strangely we link here, this is actually just to force a network evaluation
// The assert is then processed and the rule unlinks then.
// This is because we need the first RightTuple to link with it's blocked
if ( stagedInsertWasEmpty ) {
memory.setNodeDirtyWithoutNotify();
}
// NotNodes can only be unlinked, if they have no variable constraints
memory.linkNode( wm );
} else if ( stagedInsertWasEmpty ) {
Expand All @@ -175,12 +175,12 @@ public void doDeleteRightTuple(final RightTuple rightTuple,
final InternalWorkingMemory wm,
final BetaMemory memory) {
TupleSets<RightTuple> stagedRightTuples = memory.getStagedRightTuples();
if ( stagedRightTuples.isEmpty() ) {
memory.setNodeDirtyWithoutNotify();
}
boolean stagedDeleteWasEmpty = stagedRightTuples.addDelete( rightTuple );

if ( memory.getAndDecCounter() == 1 && isEmptyBetaConstraints() ) {
if ( stagedDeleteWasEmpty ) {
memory.setNodeDirtyWithoutNotify();
}
// NotNodes can only be unlinked, if they have no variable constraints
memory.linkNode( wm );
} else if ( stagedDeleteWasEmpty ) {
Expand Down

0 comments on commit b08c1cc

Please sign in to comment.