Browse Source

elim divides

cxgeorge 24 years ago
parent
commit
ed94f8085c
1 changed files with 10 additions and 6 deletions
  1. 10 6
      panda/src/express/trueClock.cxx

+ 10 - 6
panda/src/express/trueClock.cxx

@@ -42,8 +42,10 @@ TrueClock *TrueClock::_global_ptr = NULL;
 static BOOL _has_high_res;
 static BOOL _has_high_res;
 static PN_int64 _frequency;
 static PN_int64 _frequency;
 static PN_int64 _init_count;
 static PN_int64 _init_count;
+double _fFrequency,_recip_fFrequency;
 static DWORD _init_tc;
 static DWORD _init_tc;
 static bool _paranoid_clock;
 static bool _paranoid_clock;
+const double _0001 = 1.0/1000.0;
 
 
 void get_true_time_of_day(ulong &sec, ulong &usec) {
 void get_true_time_of_day(ulong &sec, ulong &usec) {
   struct timeb tb;
   struct timeb tb;
@@ -55,7 +57,7 @@ void get_true_time_of_day(ulong &sec, ulong &usec) {
 double TrueClock::
 double TrueClock::
 get_long_time() const {
 get_long_time() const {
   DWORD tc = GetTickCount();
   DWORD tc = GetTickCount();
-  return (double)(tc - _init_tc) / 1000.0;
+  return (double)(tc - _init_tc) * _0001;
 }
 }
 
 
 double TrueClock::
 double TrueClock::
@@ -64,21 +66,21 @@ get_short_time() const {
     LARGE_INTEGER count;
     LARGE_INTEGER count;
     QueryPerformanceCounter(&count);
     QueryPerformanceCounter(&count);
 
 
-    double time = (double)(count.QuadPart - _init_count) / (double)_frequency;
+    double time = (double)(count.QuadPart - _init_count) * _recip_fFrequency;
 
 
     if (_paranoid_clock) {
     if (_paranoid_clock) {
       // Now double-check the high-resolution clock against the system
       // Now double-check the high-resolution clock against the system
       // clock.
       // clock.
       DWORD tc = GetTickCount();
       DWORD tc = GetTickCount();
-      double sys_time = (double)(tc - _init_tc) / 1000.0;
+      double sys_time = (double)(tc - _init_tc) * _0001;
       if (fabs(time - sys_time) > 0.5) {
       if (fabs(time - sys_time) > 0.5) {
         // Too much variance!
         // Too much variance!
         express_cat.info()
         express_cat.info()
           << "Clock error!  High resolution clock reads " << time 
           << "Clock error!  High resolution clock reads " << time 
           << " while system clock reads " << sys_time << ".\n";
           << " while system clock reads " << sys_time << ".\n";
         _init_count = 
         _init_count = 
-          (PN_int64)(count.QuadPart - sys_time * (double)_frequency);
-        time = (double)(count.QuadPart - _init_count) / (double)_frequency;
+          (PN_int64)(count.QuadPart - sys_time * _fFrequency);
+        time = (double)(count.QuadPart - _init_count) * _recip_fFrequency;
         express_cat.info()
         express_cat.info()
           << "High resolution clock reset to " << time << ".\n";
           << "High resolution clock reset to " << time << ".\n";
       }
       }
@@ -89,7 +91,7 @@ get_short_time() const {
   } else {
   } else {
     // No high-resolution clock; return the best information we have.
     // No high-resolution clock; return the best information we have.
     DWORD tc = GetTickCount();
     DWORD tc = GetTickCount();
-    return (double)(tc - _init_tc) / 1000.0;
+    return (double)(tc - _init_tc) * _0001;
   }
   }
 }
 }
 
 
@@ -98,6 +100,8 @@ TrueClock() {
   _has_high_res = false;
   _has_high_res = false;
   if (get_use_high_res_clock()) {
   if (get_use_high_res_clock()) {
     _has_high_res = QueryPerformanceFrequency((LARGE_INTEGER *)&_frequency);
     _has_high_res = QueryPerformanceFrequency((LARGE_INTEGER *)&_frequency);
+    _fFrequency = (double) _frequency;
+    _recip_fFrequency = 1.0/_fFrequency;
   }
   }
 
 
   _paranoid_clock = get_paranoid_clock();
   _paranoid_clock = get_paranoid_clock();