fix: Using built-in cache of getters for ULID#time

dev
LeMarsu 2019-09-30 19:03:52 +02:00
parent fb93e63fe5
commit 0682973758
1 changed files with 5 additions and 7 deletions

View File

@ -13,6 +13,11 @@ module Ulid
def_hash @bytes
getter bytes : Bytes
getter time : Time do
ms = 0u64
6.times { |i| ms |= @bytes[5 - i].to_u64 << (i * 8) }
Time.unix_ms(ms)
end
def initialize(bytes : Bytes)
initialize(bytes, true)
@ -56,13 +61,6 @@ module Ulid
io << ">"
end
def time : Time
return time if time = @time
ms = 0u64
6.times { |i| ms |= @bytes[5 - i].to_u64 << (i * 8) }
@time = Time.unix_ms(ms)
end
def <=>(other : ULID)
@bytes.<=>(other.@bytes)
end