aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authornyamatongwe <devnull@localhost>2001-11-15 01:54:12 +0000
committernyamatongwe <devnull@localhost>2001-11-15 01:54:12 +0000
commitbedc366948fe5e3b38d7d058cb53c829406e6ea2 (patch)
tree5b69743d5e1eec0f07667aee70f327373593bda4
parent9fc0dc5140d4299dbf0aed8aead1d89892aa2c00 (diff)
downloadscintilla-mirror-bedc366948fe5e3b38d7d058cb53c829406e6ea2.tar.gz
Changed to a more typesafe definition of ElapsedTime.
-rw-r--r--gtk/PlatGTK.cxx42
-rw-r--r--include/Platform.h3
-rw-r--r--win32/PlatWin.cxx39
3 files changed, 37 insertions, 47 deletions
diff --git a/gtk/PlatGTK.cxx b/gtk/PlatGTK.cxx
index 7ecd1cbee..827835a75 100644
--- a/gtk/PlatGTK.cxx
+++ b/gtk/PlatGTK.cxx
@@ -886,42 +886,24 @@ void Menu::Show(Point pt, Window &) {
gtk_item_factory_popup(reinterpret_cast<GtkItemFactory *>(id), pt.x - 4, pt.y, 3, 0);
}
-static double DoublePack(glong a, glong b) {
- double d;
- long *lp = reinterpret_cast<glong *>(&d);
- lp[0] = a;
- lp[1] = b;
- return d;
-}
-
-static void DoubleUnpack(double d, glong &a, glong &b) {
- long *lp = reinterpret_cast<glong *>(&d);
- a = lp[0];
- b = lp[1];
-}
-
-static double Now() {
+ElapsedTime::ElapsedTime() {
GTimeVal curTime;
g_get_current_time(&curTime);
- return DoublePack(curTime.tv_sec, curTime.tv_usec);
-}
-
-ElapsedTime::ElapsedTime() {
- beginTime = Now();
+ bigBit = curTime.tv_sec;
+ littleBit = curTime.tv_usec;
}
double ElapsedTime::Duration(bool reset) {
- double endTime = Now();
- GTimeVal tvStart;
- DoubleUnpack(beginTime, tvStart.tv_sec, tvStart.tv_usec);
- GTimeVal tvEnd;
- DoubleUnpack(endTime, tvEnd.tv_sec, tvEnd.tv_usec);
- double result = tvEnd.tv_sec - tvStart.tv_sec;
- result *= 1000000;
- result += tvEnd.tv_usec - tvStart.tv_usec;
- result /= 1000000;
+ GTimeVal curTime;
+ g_get_current_time(&curTime);
+ long endBigBit = curTime.tv_sec;
+ long endLittleBit = curTime.tv_usec;
+ double result = 1000000.0 * (endBigBit - bigBit);
+ result += endLittleBit - littleBit;
+ result /= 1000000.0;
if (reset) {
- beginTime = endTime;
+ bigBit = endBigBit;
+ littleBit = endLittleBit;
}
return result;
}
diff --git a/include/Platform.h b/include/Platform.h
index fc0e1fe79..80f5af2e3 100644
--- a/include/Platform.h
+++ b/include/Platform.h
@@ -387,7 +387,8 @@ public:
};
class ElapsedTime {
- double beginTime;
+ long bigBit;
+ long littleBit;
public:
ElapsedTime();
double Duration(bool reset=false);
diff --git a/win32/PlatWin.cxx b/win32/PlatWin.cxx
index d227aa7a1..7a1ef5f9c 100644
--- a/win32/PlatWin.cxx
+++ b/win32/PlatWin.cxx
@@ -877,38 +877,45 @@ static bool initialisedET = false;
static bool usePerformanceCounter = false;
static LARGE_INTEGER frequency;
-static double Now() {
- if (usePerformanceCounter) {
- LARGE_INTEGER timeVal;
- ::QueryPerformanceCounter(&timeVal);
- return *(reinterpret_cast<double *>(&timeVal));
- } else {
- return clock();
- }
-}
-
ElapsedTime::ElapsedTime() {
if (!initialisedET) {
usePerformanceCounter = ::QueryPerformanceFrequency(&frequency);
initialisedET = true;
}
- beginTime = Now();
+ if (usePerformanceCounter) {
+ LARGE_INTEGER timeVal;
+ ::QueryPerformanceCounter(&timeVal);
+ bigBit = timeVal.HighPart;
+ littleBit = timeVal.LowPart;
+ } else {
+ bigBit = clock();
+ }
}
double ElapsedTime::Duration(bool reset) {
- double endTime = Now();
double result;
+ long endBigBit;
+ long endLittleBit;
+
if (usePerformanceCounter) {
- LARGE_INTEGER lBegin = *(reinterpret_cast<LARGE_INTEGER *>(&beginTime));
- LARGE_INTEGER lEnd = *(reinterpret_cast<LARGE_INTEGER *>(&endTime));
+ LARGE_INTEGER lEnd;
+ ::QueryPerformanceCounter(&lEnd);
+ endBigBit = lEnd.HighPart;
+ endLittleBit = lEnd.LowPart;
+ LARGE_INTEGER lBegin;
+ lBegin.HighPart = bigBit;
+ lBegin.LowPart = littleBit;
double elapsed = lEnd.QuadPart - lBegin.QuadPart;
result = elapsed / static_cast<double>(frequency.QuadPart);
} else {
- double elapsed = endTime - beginTime;
+ endBigBit = clock();
+ endLittleBit = 0;
+ double elapsed = endBigBit - bigBit;
result = elapsed / CLOCKS_PER_SEC;
}
if (reset) {
- beginTime = endTime;
+ bigBit = endBigBit;
+ littleBit = endLittleBit;
}
return result;
}