From: blackh <gra...@li...> - 2003-08-16 20:21:08
|
blackh Sat Aug 16 13:21:08 2003 EDT Modified files: /grapevine/cpp Engine.cpp Fact.cpp Fact.h Object.cpp Object.h Operation.cpp Persist.cpp RuleState.cpp Log: Performance improvement of about 20% for vectorDistanceBenchmark. Index: grapevine/cpp/RuleState.cpp diff -u grapevine/cpp/RuleState.cpp:1.5 grapevine/cpp/RuleState.cpp:1.6 --- grapevine/cpp/RuleState.cpp:1.5 Thu Aug 7 23:05:43 2003 +++ grapevine/cpp/RuleState.cpp Sat Aug 16 13:21:08 2003 @@ -1,4 +1,4 @@ -// $Id: RuleState.cpp,v 1.5 2003/08/08 06:05:43 blackh Exp $ +// $Id: RuleState.cpp,v 1.6 2003/08/16 20:21:08 blackh Exp $ #include "RuleState.h" @@ -121,7 +121,7 @@ */ /*static*/ int RuleState::combineCompare(const RuleState& left, const RuleState& right, const IndexVector& indexVector) { - int leftSize = left.variables.size(); // !!! + int leftSize = left.variables.size(); int rightSize = right.variables.size(); // Compare only the fields specified by the indexVector. @@ -129,15 +129,18 @@ int index = (*it).first; SortStyle sortStyle = (*it).second; if (index < leftSize && index < rightSize) { - Object vLeft; - Object vRight; - if ((sortStyle & SSM_TYPE) == SS_ALPHA) { - vLeft = left.variables[index].asString(); - vRight = right.variables[index].asString(); // !!! - } - else { - vLeft = left.variables[index].asBigInteger(); - vRight = right.variables[index].asBigInteger(); + Object vLeft = left.variables[index]; + Object vRight = right.variables[index]; + int sortType = sortStyle & SSM_TYPE; + switch (sortStyle & SSM_TYPE) { + case SS_ALPHA: + vLeft = vLeft.asString(); + vRight = vRight.asString(); + break; + case SS_NUMERIC: + vLeft = vLeft.asBigInteger(); + vRight = vRight.asBigInteger(); + break; } // Assume both are bound. The validity of this assumption depends on @@ -149,10 +152,12 @@ // variable in this case changing the basic nature of the match that follows. // Compare the variables as one might compare characters in a string. - if (vLeft < vRight) - return ((sortStyle & SSM_DIRECTION) == SS_ASCENDING) ? -1 : 1; - if (!(vLeft == vRight)) - return ((sortStyle & SSM_DIRECTION) == SS_ASCENDING) ? 1 : -1; + if (vLeft != vRight) { + if (vLeft < vRight) + return ((sortStyle & SSM_DIRECTION) == SS_ASCENDING) ? -1 : 1; + else + return ((sortStyle & SSM_DIRECTION) == SS_ASCENDING) ? 1 : -1; + } } } |