Skip to content

Commit

Permalink
Use Int#bit_length instead of Math.log2 followed by #to_i (#13440)
Browse files Browse the repository at this point in the history
  • Loading branch information
HertzDevil committed May 8, 2023
1 parent 2aeaea0 commit 98c091e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/hash.cr
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ class Hash(K, V)
@indices_bytesize = 1
end

@indices_size_pow2 = Math.log2(initial_indices_size).to_u8
@indices_size_pow2 = initial_indices_size.bit_length.to_u8 - 1
end

@size = 0
Expand Down
4 changes: 2 additions & 2 deletions src/slice/sort.cr
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
struct Slice(T)
protected def self.intro_sort!(a, n)
return if n < 2
quick_sort_for_intro_sort!(a, n, Math.log2(n).to_i * 2)
quick_sort_for_intro_sort!(a, n, (n.bit_length - 1) * 2)
insertion_sort!(a, n)
end

Expand Down Expand Up @@ -99,7 +99,7 @@ struct Slice(T)

protected def self.intro_sort!(a, n, comp)
return if n < 2
quick_sort_for_intro_sort!(a, n, Math.log2(n).to_i * 2, comp)
quick_sort_for_intro_sort!(a, n, (n.bit_length - 1) * 2, comp)
insertion_sort!(a, n, comp)
end

Expand Down

0 comments on commit 98c091e

Please sign in to comment.