Credence.Pattern.NoIntegerToStringDigits (credence v0.4.1)

Copy Markdown

Performance rule: Detects converting an integer to a string representation in a given base and then to a charlist, when Integer.digits/2 can extract the digits directly as a list of integers.

The string conversion creates an intermediate binary and then a charlist, both of which are unnecessary allocations when you just need the digits.

Bad

String.to_charlist(Integer.to_string(number, 2))
Integer.to_string(number, 2) |> String.to_charlist()

Good

Integer.digits(number, 2)