Skip to content

Commit

Permalink
Use Slice(UInt8)#fill in the standard library (#11468)
Browse files Browse the repository at this point in the history
  • Loading branch information
HertzDevil authored Nov 23, 2021
1 parent 59f648e commit 5f8f4fb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/int.cr
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ struct Int
if precision > count
difference = precision - count
ptr -= difference
Intrinsics.memset(ptr, '0'.ord.to_u8, difference, false)
Slice.new(ptr, difference).fill('0'.ord.to_u8)
count += difference
end

Expand All @@ -678,7 +678,7 @@ struct Int
buffer += 1
end

Intrinsics.memset(buffer, '0'.ord.to_u8, precision - count, false)
Slice.new(buffer, precision - count).fill('0'.ord.to_u8)
ptr.copy_to(buffer + precision - count, count)
{len, len}
end
Expand Down
6 changes: 3 additions & 3 deletions src/string.cr
Original file line number Diff line number Diff line change
Expand Up @@ -3024,7 +3024,7 @@ class String
return ""
elsif bytesize == 1
return String.new(times) do |buffer|
Intrinsics.memset(buffer.as(Void*), to_unsafe[0], times, false)
Slice.new(buffer, times).fill(to_unsafe[0])
{times, times}
end
end
Expand Down Expand Up @@ -4220,7 +4220,7 @@ class String
String.new(new_bytesize) do |buffer|
if leftpadding > 0
if count == 1
Intrinsics.memset(buffer.as(Void*), char.ord.to_u8, leftpadding.to_u32, false)
Slice.new(buffer, leftpadding).fill(char.ord.to_u8)
buffer += leftpadding
else
leftpadding.times do
Expand All @@ -4233,7 +4233,7 @@ class String
buffer += bytesize
if rightpadding > 0
if count == 1
Intrinsics.memset(buffer.as(Void*), char.ord.to_u8, rightpadding.to_u32, false)
Slice.new(buffer, rightpadding).fill(char.ord.to_u8)
else
rightpadding.times do
buffer.copy_from(bytes.to_unsafe, count)
Expand Down

0 comments on commit 5f8f4fb

Please sign in to comment.