timeInfoFromOSTime - cache last return
authorClaus Gittinger <cg@exept.de>
Mon, 10 Nov 2003 14:27:59 +0100
changeset 7739 d09af69f0466
parent 7738 d08da93d4a5f
child 7740 5a9d544b8906
timeInfoFromOSTime - cache last return
AbstractOperatingSystem.st
UnixOperatingSystem.st
--- a/AbstractOperatingSystem.st	Mon Nov 10 13:00:39 2003 +0100
+++ b/AbstractOperatingSystem.st	Mon Nov 10 14:27:59 2003 +0100
@@ -4764,8 +4764,7 @@
     |divMod ret|
 
     divMod := osTime divMod:1000.
-    ret := self timeInfoFromSeconds:(divMod at:1) localTime:true.
-    ret milliseconds:(divMod at:2).
+    ret := self timeInfoFromSeconds:(divMod at:1) milliseconds:(divMod at:2) localTime:true.
     ^ ret
 
     "
@@ -4801,8 +4800,7 @@
     |divMod ret|
 
     divMod := osTime divMod:1000.
-    ret := self timeInfoFromSeconds:(divMod at:1) localTime:false.
-    ret milliseconds:(divMod at:2).
+    ret := self timeInfoFromSeconds:(divMod at:1) milliseconds:(divMod at:2) localTime:false.
     ^ ret
 
     "
@@ -5000,6 +4998,13 @@
     "return a timeInfo structure containing values for the given OS-second value.
      An internal helper"
 
+    ^ self timeInfoFromSeconds:osSeconds milliseconds:0 localTime:isLocalTime
+!
+
+timeInfoFromSeconds:osSeconds milliseconds:osMilliSeconds localTime:isLocalTime
+    "return a timeInfo structure containing values for the given OS-second value.
+     An internal helper"
+
     self subclassResponsibility
 ! !
 
@@ -5373,38 +5378,39 @@
     "backward compatibility"
 
     self obsoleteMethodWarning:'use accessor for index ', index printString.
+
     index == 1 ifTrue:[
-	^ self year.
+        ^ self year.
     ].
     index == 2 ifTrue:[
-	^ self month.
+        ^ self month.
     ].
     index == 3 ifTrue:[
-	^ self day.
+        ^ self day.
     ].
     index == 4 ifTrue:[
-	^ self hours.
+        ^ self hours.
     ].
     index == 5 ifTrue:[
-	^ self minutes.
+        ^ self minutes.
     ].
     index == 6 ifTrue:[
-	^ self seconds.
+        ^ self seconds.
     ].
     index == 7 ifTrue:[
-	^ self utcOffset.
+        ^ self utcOffset.
     ].
     index == 8 ifTrue:[
-	^ self dst.
+        ^ self dst.
     ].
     index == 9 ifTrue:[
-	^ self milliseconds.
+        ^ self milliseconds.
     ].
     index == 10 ifTrue:[
-	^ self dayInYear.
+        ^ self dayInYear.
     ].
     index == 11 ifTrue:[
-	^ self dayInWeek.
+        ^ self dayInWeek.
     ].
     self subscriptBoundsError:index
 !
@@ -5457,6 +5463,22 @@
     ^ year
 !
 
+year:yearArg month:monthArg day:dayArg hours:hoursArg minutes:minutesArg seconds:secondsArg milliseconds:millisecondsArg utcOffset:utcOffsetArg dst:dstArg dayInYear:dayInYearArg dayInWeek:dayInWeekArg 
+    "set instance variables (automatically generated)"
+
+    year := yearArg.
+    month := monthArg.
+    day := dayArg.
+    hours := hoursArg.
+    minutes := minutesArg.
+    seconds := secondsArg.
+    milliseconds := millisecondsArg.
+    utcOffset := utcOffsetArg.
+    dst := dstArg.
+    dayInYear := dayInYearArg.
+    dayInWeek := dayInWeekArg.
+!
+
 year:yearArg month:monthArg day:dayArg hours:hoursArg minutes:minutesArg seconds:secondsArg utcOffset:utcOffsetArg dst:dstArg dayInYear:dayInYearArg dayInWeek:dayInWeekArg 
     "set instance variables (automatically generated)"
 
@@ -5475,7 +5497,7 @@
 !AbstractOperatingSystem class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/AbstractOperatingSystem.st,v 1.115 2003-11-03 16:40:41 stefan Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/AbstractOperatingSystem.st,v 1.116 2003-11-10 13:27:59 cg Exp $'
 ! !
 
 AbstractOperatingSystem initialize!
--- a/UnixOperatingSystem.st	Mon Nov 10 13:00:39 2003 +0100
+++ b/UnixOperatingSystem.st	Mon Nov 10 14:27:59 2003 +0100
@@ -14,7 +14,9 @@
 
 AbstractOperatingSystem subclass:#UnixOperatingSystem
 	instanceVariableNames:''
-	classVariableNames:'HostName DomainName SlowFork ForkFailed CurrentDirectory'
+	classVariableNames:'HostName DomainName SlowFork ForkFailed CurrentDirectory
+		LastTimeInfo LastTimeInfoSeconds LastTimeInfoMilliseconds
+		LastTimeInfoIsLocal'
 	poolDictionaries:''
 	category:'OS-Unix'
 !
@@ -8424,7 +8426,7 @@
     "
 !
 
-timeInfoFromSeconds:osSeconds localTime:isLocalTime
+timeInfoFromSeconds:osSeconds milliseconds:osMilliseconds localTime:isLocalTime
     "return a timeInfo structure containing values for the given
      OS-second value.
      An internal helper"
@@ -8432,19 +8434,36 @@
     |year month day hours minutes seconds utcOffset 
      dst yDay wDay info|
 
-    info := self timeInfoClass new.
 %{
     struct tm *tmPtr;
     INT t;
     TIME_T tt;
 
     t = __longIntVal(osSeconds);
+
+    /* try cache */
+    {
+        OBJ lastSeconds, lastTimeInfo;
+
+        lastSeconds = @global(LastTimeInfoSeconds);
+        if (lastSeconds 
+         && (__longIntVal(lastSeconds) == t)
+         && (@global(LastTimeInfoMilliseconds) == osMilliseconds)
+         && (@global(LastTimeInfoIsLocal) == isLocalTime)
+        ) {
+            lastTimeInfo = @global(LastTimeInfo);
+            if (lastTimeInfo != nil) {
+                RETURN (lastTimeInfo);
+            }
+        }
+    }
+
     tt = (TIME_T)t;
 
     if (isLocalTime == true) {
-	tmPtr = localtime(&tt);
+        tmPtr = localtime(&tt);
     } else {
-	tmPtr = gmtime(&tt);
+        tmPtr = gmtime(&tt);
     }
     hours = __MKSMALLINT(tmPtr->tm_hour);
     minutes = __MKSMALLINT(tmPtr->tm_min);
@@ -8459,21 +8478,32 @@
     utcOffset = __MKSMALLINT(TIMEZONE(tmPtr));
     dst = (tmPtr->tm_isdst == 0 ? false : true);
 %}.
+    info := self timeInfoClass new.
     info
-	year:year
-	month:month
-	day:day
-	hours:hours
-	minutes:minutes
-	seconds:seconds
-	utcOffset:utcOffset
-	dst:dst
-	dayInYear:yDay
-	dayInWeek:wDay.
+        year:year
+        month:month
+        day:day
+        hours:hours
+        minutes:minutes
+        seconds:seconds
+        milliseconds:osMilliseconds
+        utcOffset:utcOffset
+        dst:dst
+        dayInYear:yDay
+        dayInWeek:wDay.
+
+%{
+    @global(LastTimeInfo) = info;                       __GSTORE(info); 
+    @global(LastTimeInfoSeconds) = osSeconds;           __GSTORE(osSeconds); 
+    @global(LastTimeInfoMilliseconds) = osMilliseconds; __GSTORE(osMilliseconds); 
+    @global(LastTimeInfoIsLocal) = isLocalTime;         __GSTORE(isLocalTime); 
+%}.
+
     ^ info
 
     "
-     OperatingSystem timeInfoFromSeconds:0 localTime:false
+     OperatingSystem timeInfoFromSeconds:0 localTime:false 
+     OperatingSystem timeInfoFromSeconds:3600 localTime:false 
     "
 ! !
 
@@ -12140,7 +12170,7 @@
 !UnixOperatingSystem class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/UnixOperatingSystem.st,v 1.191 2003-11-10 12:00:39 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/UnixOperatingSystem.st,v 1.192 2003-11-10 13:27:35 cg Exp $'
 ! !
 
 UnixOperatingSystem initialize!