Skip to content

Commit

Permalink
Refactor missing unsafe_as (#5341)
Browse files Browse the repository at this point in the history
  • Loading branch information
bew authored and RX14 committed Dec 3, 2017
1 parent b747f5f commit 32319e3
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/crystal/system/unix/getrandom.cr
Expand Up @@ -42,7 +42,7 @@ module Crystal::System::Random
if @@getrandom_available
buf = uninitialized UInt8[1]
getrandom(buf.to_slice)
buf.to_unsafe.as(UInt8*).value
buf.unsafe_as(UInt8)
elsif urandom = @@urandom
urandom.read_byte.not_nil!
else
Expand Down
4 changes: 2 additions & 2 deletions src/io/byte_format.cr
Expand Up @@ -149,14 +149,14 @@ module IO::ByteFormat
buffer = uninitialized UInt8[{{bytesize}}]
io.read_fully(buffer.to_slice)
buffer.reverse! unless SystemEndian == self
buffer.to_unsafe.as(Pointer({{type.id}})).value
buffer.unsafe_as({{type.id}})
end

def self.decode(type : {{type.id}}.class, bytes : Bytes)
buffer = uninitialized UInt8[{{bytesize}}]
bytes.to_slice[0, {{bytesize}}].copy_to(buffer.to_slice)
buffer.reverse! unless SystemEndian == self
buffer.to_unsafe.as(Pointer({{type.id}})).value
buffer.unsafe_as({{type.id}})
end
{% end %}
end
Expand Down
2 changes: 1 addition & 1 deletion src/random/secure.cr
Expand Up @@ -45,7 +45,7 @@ module Random::Secure
end
else
random_bytes(buf.to_slice)
buf.to_unsafe.as({{type}}*).value
buf.unsafe_as({{type}})
end
end
{% end %}
Expand Down

0 comments on commit 32319e3

Please sign in to comment.