зеркало из https://github.com/github/ruby.git
[ruby/securerandom] Increase speed of UUID generation
https://github.com/ruby/securerandom/commit/b587b8c7cb
This commit is contained in:
Родитель
2b96737636
Коммит
e86b4c29fc
|
@ -168,10 +168,10 @@ module Random::Formatter
|
|||
# See RFC4122[https://datatracker.ietf.org/doc/html/rfc4122] for details of UUID.
|
||||
#
|
||||
def uuid
|
||||
ary = random_bytes(16).unpack("NnnnnN")
|
||||
ary[2] = (ary[2] & 0x0fff) | 0x4000
|
||||
ary[3] = (ary[3] & 0x3fff) | 0x8000
|
||||
"%08x-%04x-%04x-%04x-%04x%08x" % ary
|
||||
ary = random_bytes(16)
|
||||
ary.setbyte(6, (ary.getbyte(6) & 0x0f) | 0x40)
|
||||
ary.setbyte(8, (ary.getbyte(8) & 0x3f) | 0x80)
|
||||
ary.unpack("H8H4H4H4H12").join(?-)
|
||||
end
|
||||
|
||||
alias uuid_v4 uuid
|
||||
|
|
Загрузка…
Ссылка в новой задаче