fix: Using built-in cache of getters for ULID#time
parent
fb93e63fe5
commit
0682973758
12
src/ulid.cr
12
src/ulid.cr
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue