From 8454cb916c4ec8a25f39fff85930d13a159da84b Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 15 Sep 2015 15:15:26 -0700 Subject: [PATCH] avoid branching by using %= operator --- libraries/networking/src/udt/PacketTimeWindow.cpp | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/libraries/networking/src/udt/PacketTimeWindow.cpp b/libraries/networking/src/udt/PacketTimeWindow.cpp index 915810b93e..0c95d21bc6 100644 --- a/libraries/networking/src/udt/PacketTimeWindow.cpp +++ b/libraries/networking/src/udt/PacketTimeWindow.cpp @@ -102,9 +102,7 @@ void PacketTimeWindow::onPacketArrival() { _packetIntervals[_currentPacketInterval++] = duration_cast(now - _lastPacketTime).count(); // reset the currentPacketInterval index when it wraps - if (_currentPacketInterval == _numPacketIntervals) { - _currentPacketInterval = 0; - } + _currentPacketInterval %= _numPacketIntervals; } // remember this as the last packet arrival time @@ -123,7 +121,5 @@ void PacketTimeWindow::onProbePair2Arrival() { _probeIntervals[_currentProbeInterval++] = duration_cast(now - _firstProbeTime).count(); // reset the currentProbeInterval index when it wraps - if (_currentProbeInterval == _numProbeIntervals) { - _currentProbeInterval = 0; - } + _currentProbeInterval %= _numProbeIntervals; }