[Common-cvs] util/pub timeval.h,1.10,1.11

[Common-cvs] util/pub timeval.h,1.10,1.11

dyek at helixcommunity.org dyek at helixcommunity.org
Mon Nov 12 10:30:22 PST 2007


Update of /cvsroot/common/util/pub
In directory cvs01.internal.helixcommunity.org:/tmp/cvs-serv4702

Modified Files:
	timeval.h 
Log Message:
Commit CR from Massimo Perga <massimo.perga at gmail.com>.

Reimplement Timeval operators without loops.
This change is NOT wrapped in __x86_64__ and _UNIX defines, 
as in other branches.

File Modified:
common/util/pub/timeval.h

Refer to the following URL for more information:
http://lists.helixcommunity.org/pipermail/helix-client-dev/2007-October/006833.html




Index: timeval.h
===================================================================
RCS file: /cvsroot/common/util/pub/timeval.h,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- timeval.h	6 Jul 2007 20:39:23 -0000	1.10
+++ timeval.h	12 Nov 2007 18:30:19 -0000	1.11
@@ -44,6 +44,7 @@
  *    http://www.helixcommunity.org/content/tck
  * 
  * Contributor(s):
+ *    Massimo Perga <massimo.perga at gmail.com>
  * 
  * ***** END LICENSE BLOCK ***** */
 
@@ -158,9 +159,11 @@
 inline Timeval& Timeval::operator +=(const Timeval& b) {
         tv_sec += b.tv_sec;
         tv_usec += b.tv_usec;
-        while (tv_usec >= SECOND) {
-                tv_sec++;
-                tv_usec -= SECOND;
+
+        if(tv_usec >= SECOND)
+        {
+            tv_sec += tv_usec / SECOND;
+            tv_usec = tv_usec % SECOND;
         }
         return *this;
 }
@@ -179,9 +182,10 @@
 #endif
         tv_sec -= b.tv_sec;
         tv_usec -= b.tv_usec;
-        while (tv_usec < 0) {
-                tv_sec--;
-                tv_usec += SECOND;
+        if(tv_usec < 0)
+        {
+            tv_sec -= tv_usec / SECOND;
+            tv_usec = tv_usec % SECOND;
         }
         return *this;
 }
@@ -190,9 +194,10 @@
         Timeval c;
         c.tv_sec = a.tv_sec + b.tv_sec;
         c.tv_usec = a.tv_usec + b.tv_usec;
-        while (c.tv_usec >= SECOND) {
-                c.tv_sec++;
-                c.tv_usec -= SECOND;
+        if(c.tv_usec >= SECOND)
+        {
+            c.tv_sec += c.tv_usec / SECOND;
+            c.tv_usec = c.tv_usec % SECOND;
         }
         return c;
 }
@@ -209,9 +214,10 @@
 #endif
         c.tv_sec = a.tv_sec - b.tv_sec;
         c.tv_usec = a.tv_usec - b.tv_usec;
-        while (c.tv_usec < 0) {
-                c.tv_sec--;
-                c.tv_usec += SECOND;
+        if(c.tv_usec < 0)
+        {
+            c.tv_sec -= c.tv_usec / SECOND;
+            c.tv_usec = c.tv_usec % SECOND;
         }
         return c;
 }




More information about the Common-cvs mailing list
 

Site Map   |   Terms of Use   |   Privacy Policy   |   Contact Us

Copyright © 1995-2007 RealNetworks, Inc. All rights reserved. RealNetworks and Helix are trademarks of RealNetworks.
All other trademarks or registered trademarks are the property of their respective holders.