Skip to content

Commit 8497f3f

Browse files
committed
Fix DecayParticleModel::less_than(...) to be better behaved.
1 parent c7c2bea commit 8497f3f

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

src/ReferencePhotopeakDisplay.cpp

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -523,32 +523,34 @@ namespace
523523

524524
}//namespace
525525

526-
bool DecayParticleModel::less_than( const DecayParticleModel::RowData &lhs,
527-
const DecayParticleModel::RowData &rhs,
526+
bool DecayParticleModel::less_than( const DecayParticleModel::RowData &lhs_input,
527+
const DecayParticleModel::RowData &rhs_input,
528528
const DecayParticleModel::Column c,
529529
const SortOrder order )
530530
{
531-
532-
bool less = false;
533-
531+
const bool less = (order == Wt::AscendingOrder);
532+
533+
const DecayParticleModel::RowData &lhs = less ? lhs_input : rhs_input;
534+
const DecayParticleModel::RowData &rhs = less ? rhs_input : lhs_input;
535+
534536
switch( c )
535537
{
536-
case kEnergy: less = (lhs.energy < rhs.energy); break;
537-
case kBranchingRatio: less = (lhs.branchRatio < rhs.branchRatio); break;
538+
case kEnergy: return (lhs.energy < rhs.energy);
539+
case kBranchingRatio: return (lhs.branchRatio < rhs.branchRatio);
538540
case kResponsibleNuc:
539541
if( !lhs.responsibleNuc || !rhs.responsibleNuc )
540-
less = false;
542+
return lhs.responsibleNuc < rhs.responsibleNuc;
541543
else
542-
less = SandiaDecay::Nuclide::lessThanForOrdering( lhs.responsibleNuc, rhs.responsibleNuc );
544+
return SandiaDecay::Nuclide::lessThanForOrdering( lhs.responsibleNuc, rhs.responsibleNuc );
543545
break;
544-
case kDecayMode: less = (lhs.decayMode < rhs.decayMode); break;
545-
case kParticleType: less = (lhs.particle < rhs.particle); break;
546+
case kDecayMode: return (lhs.decayMode < rhs.decayMode);
547+
case kParticleType: return (lhs.particle < rhs.particle);
546548
case kNumColumn: return false;
547549
}//switch( r )
548550

549-
if( order == Wt::AscendingOrder )
550-
return less;
551-
return !less;
551+
assert( 0 );
552+
553+
return false;
552554
}//less_than(...)
553555

554556

0 commit comments

Comments
 (0)