[squeak-dev] The Inbox: Chronology-Core-ul.22.mcz

Eliot Miranda eliot.miranda at gmail.com
Mon Jan 14 15:07:23 UTC 2019


Hi Levente,

> On Jan 14, 2019, at 4:18 AM, commits at source.squeak.org wrote:
> 
> Levente Uzonyi uploaded a new version of Chronology-Core to project The Inbox:
> http://source.squeak.org/inbox/Chronology-Core-ul.22.mcz
> 
> ==================== Summary ====================
> 
> Name: Chronology-Core-ul.22
> Author: ul
> Time: 14 January 2019, 1:08:48.177246 pm
> UUID: 025b4802-6281-4674-937e-a345e5a6aded
> Ancestors: Chronology-Core-ul.21
> 
> - added an accessor to Time's ClockPolicy, so that tests can depend on its current value
> - optimized various DateAndTime methods
> 
> =============== Diff against Chronology-Core-ul.21 ===============
> 
> Item was changed:
>  ----- Method: DateAndTime>>= (in category 'ansi protocol') -----
>  = aDateAndTimeOrTimeStamp
>      "Equal if the absolute time values match, regardless of local time transform"
> + 
>      self == aDateAndTimeOrTimeStamp ifTrue: [ ^ true ].
> +    aDateAndTimeOrTimeStamp species == DateAndTime ifFalse: [ ^false ].
> +    aDateAndTimeOrTimeStamp utcMicroseconds = utcMicroseconds ifTrue: [ ^true ].
> +    ^false!
> -    ^aDateAndTimeOrTimeStamp species == DateAndTime
> -        and: [ utcMicroseconds = aDateAndTimeOrTimeStamp utcMicroseconds ]!

Can we please avoid the ... ifFalse: [^false] style and keep the much nicer concise and: style?  Yes, the former is slightly faster, but not by much, and the JIT has code to minimize the difference and Sista will eliminate the difference.  The former style is so ugly.

> 
> Item was changed:
>  ----- Method: DateAndTime>>asUTC (in category 'ansi protocol') -----
>  asUTC
> 
>      localOffsetSeconds = 0 ifTrue: [ ^self ].
> +    ^self copy makeUTC!
> -    ^self copy
> -        utcMicroseconds: utcMicroseconds
> -        offset: 0
> - !
> 
> Item was changed:
>  ----- Method: DateAndTime>>asUnixTime (in category 'squeak protocol') -----
>  asUnixTime
>      "answer number of seconds since unix epoch (midnight Jan 1, 1970, UTC)"
> 
> +    ^utcMicroseconds // 1000000!
> -    ^(self - self class unixEpoch) asSeconds!
> 
> Item was changed:
>  ----- Method: DateAndTime>>dayMonthYearDo: (in category 'squeak protocol') -----
>  dayMonthYearDo: aBlock
>      "Evaluation the block with three arguments: day month, year."
> 
> +    | l n i j dd |
> -    | l n i j dd mm yyyy |
>      l := self julianDayNumber + 68569.
>      n := 4 * l // 146097.
>      l := l - (146097 * n + 3 // 4).
> +    i := l + 1 * 4000 // 1461001.
> -    i := 4000 * (l + 1) // 1461001.
>      l := l - (1461 * i // 4) + 31.
>      j := 80 * l // 2447.
>      dd := l - (2447 * j // 80).
>      l := j // 11.
> -    mm := j + 2 - (12 * l).
> -    yyyy := 100 * (n - 49) + i + l.
> 
>      ^ aBlock
>          value: dd
> +        value: -12 * l + 2 + j "month"
> +        value: n - 49 * 100 + i + l "year"!
> -        value: mm
> -        value: yyyy!
> 
> Item was changed:
>  ----- Method: DateAndTime>>floor (in category 'squeak protocol') -----
>  floor
>      "Answer a copy with magnitude rounded down to the nearest whole second"
>      ^self class
> +        utcMicroseconds: utcMicroseconds // 1000000 * 1000000
> -        utcMicroseconds: utcMicroseconds - (utcMicroseconds \\ 1000000)
>          offset: localOffsetSeconds!
> 
> Item was changed:
>  ----- Method: DateAndTime>>getSeconds (in category 'accessing') -----
>  getSeconds
> +    
> +    ^utcMicroseconds // 1000000 + localOffsetSeconds \\ 86400!
> - 
> -    | posixDays posixSeconds localSeconds |
> -    posixSeconds := utcMicroseconds // 1000000.
> -    localSeconds := posixSeconds + localOffsetSeconds.
> -    localSeconds < 0 ifTrue: [localSeconds := localSeconds \\ SecondsInDay]. "normalize"
> -    posixDays := localSeconds // SecondsInDay.
> -    ^localSeconds - (posixDays * SecondsInDay).
> - !
> 
> Item was changed:
>  ----- Method: DateAndTime>>julianDayNumber (in category 'squeak protocol') -----
>  julianDayNumber
> 
> +    ^utcMicroseconds // 1000000 + localOffsetSeconds // 86400 + PosixEpochJulianDays!
> -    | posixDays posixSeconds localSeconds negativeDays |
> -    posixSeconds := utcMicroseconds // 1000000.
> -    localSeconds := posixSeconds + localOffsetSeconds.
> -    negativeDays := 0.
> -    localSeconds < 0 ifTrue: [ "normalize"
> -            negativeDays := localSeconds // SecondsInDay.
> -            localSeconds := negativeDays * SecondsInDay + localSeconds].
> -    posixDays := localSeconds // SecondsInDay.
> -    ^posixDays + PosixEpochJulianDays - negativeDays.
> - !
> 
> Item was changed:
>  ----- Method: DateAndTime>>microsecondsFromDay:seconds:nanos:offset: (in category 'private') -----
>  microsecondsFromDay: jdn seconds: s nanos: n offset: localOffsetSeconds
> 
> +    ^jdn - PosixEpochJulianDays "days" * 86400
> +        + s - localOffsetSeconds "seconds" * 1000000
> +        + (n / 1000) "nanos"!
> -    | days totalSeconds micros |
> -    days := jdn - PosixEpochJulianDays.
> -    totalSeconds := days * 86400 + s - localOffsetSeconds. "n.g. const 86400 is faster than SecondsInDay"
> -    micros := totalSeconds * 1000000.
> -    ^micros + (n / 1000)
> - !
> 
> Item was added:
> + ----- Method: Time class>>clockPolicy (in category 'class initialization') -----
> + clockPolicy
> + 
> +    ^ClockPolicy!
> 
> 


More information about the Squeak-dev mailing list