summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorINMakrus <markus.hossner@innovative-navigation.de>2016-02-22 23:18:46 +0100
committerINMakrus <markus.hossner@innovative-navigation.de>2016-02-22 23:18:46 +0100
commit5f2fcf252b7b9790a2cb27e57f9d90ae7ea32f9e (patch)
tree442de1b04e2d153a9410955b83f05237705bee96
parent53f4a8826c9002a81f8c37acee13778c3f6674d0 (diff)
downloadATCD-5f2fcf252b7b9790a2cb27e57f9d90ae7ea32f9e.tar.gz
Update Time_Value.cpp
- Better performance by not using a loop for normalizing time values
-rw-r--r--ACE/ace/Time_Value.cpp66
1 files changed, 22 insertions, 44 deletions
diff --git a/ACE/ace/Time_Value.cpp b/ACE/ace/Time_Value.cpp
index 36ba22b8ae2..b390d815bc4 100644
--- a/ACE/ace/Time_Value.cpp
+++ b/ACE/ace/Time_Value.cpp
@@ -174,52 +174,30 @@ ACE_Time_Value::dump (void) const
void
ACE_Time_Value::normalize (bool saturate)
{
- // // ACE_OS_TRACE ("ACE_Time_Value::normalize");
- // From Hans Rohnert...
-
- if (this->tv_.tv_usec >= ACE_ONE_SECOND_IN_USECS)
- {
- /*! \todo This loop needs some optimization.
- */
- if (!saturate) // keep the conditionnal expression outside the while loop to minimize performance cost
- do
- {
- ++this->tv_.tv_sec;
- this->tv_.tv_usec -= ACE_ONE_SECOND_IN_USECS;
- }
- while (this->tv_.tv_usec >= ACE_ONE_SECOND_IN_USECS);
- else
- do
- if (this->tv_.tv_sec < ACE_Numeric_Limits<time_t>::max())
- {
- ++this->tv_.tv_sec;
- this->tv_.tv_usec -= ACE_ONE_SECOND_IN_USECS;
- }
- else
- this->tv_.tv_usec = ACE_ONE_SECOND_IN_USECS - 1;
- while (this->tv_.tv_usec >= ACE_ONE_SECOND_IN_USECS);
- }
- else if (this->tv_.tv_usec <= -ACE_ONE_SECOND_IN_USECS)
+ // ACE_OS_TRACE ("ACE_Time_Value::normalize");
+ if (this->tv_.tv_usec >= ACE_ONE_SECOND_IN_USECS ||
+ this->tv_.tv_usec <= -ACE_ONE_SECOND_IN_USECS)
{
- /*! \todo This loop needs some optimization.
- */
- if (!saturate)
- do
- {
- --this->tv_.tv_sec;
- this->tv_.tv_usec += ACE_ONE_SECOND_IN_USECS;
- }
- while (this->tv_.tv_usec <= -ACE_ONE_SECOND_IN_USECS);
+ time_t sec = abs(this->tv_.tv_usec) / ACE_ONE_SECOND_IN_USECS * (this->tv_.tv_usec > 0 ? 1 : -1);
+ suseconds_t usec = this->tv_.tv_usec - sec * ACE_ONE_SECOND_IN_USECS;
+
+ if (saturate && this->tv_.tv_sec > 0 && sec > 0 &&
+ ACE_Numeric_Limits<time_t>::max() - this->tv_.tv_sec < sec)
+ {
+ this->tv_.tv_sec = ACE_Numeric_Limits<time_t>::max();
+ this->tv_.tv_usec = ACE_ONE_SECOND_IN_USECS - 1;
+ }
+ else if (saturate && this->tv_.tv_sec < 0 && sec < 0 &&
+ ACE_Numeric_Limits<time_t>::min() - this->tv_.tv_sec > sec)
+ {
+ this->tv_.tv_sec = ACE_Numeric_Limits<time_t>::min();
+ this->tv_.tv_usec = -ACE_ONE_SECOND_IN_USECS + 1;
+ }
else
- do
- if (this->tv_.tv_sec > ACE_Numeric_Limits<time_t>::min())
- {
- --this->tv_.tv_sec;
- this->tv_.tv_usec += ACE_ONE_SECOND_IN_USECS;
- }
- else
- this->tv_.tv_usec = -ACE_ONE_SECOND_IN_USECS + 1;
- while (this->tv_.tv_usec <= -ACE_ONE_SECOND_IN_USECS);
+ {
+ this->tv_.tv_sec += sec;
+ this->tv_.tv_usec = usec;
+ }
}
if (this->tv_.tv_sec >= 1 && this->tv_.tv_usec < 0)