Skip to content

Commit

Permalink
Fix type decoder to use lazy stream instead of pre-allocated list
Browse files Browse the repository at this point in the history
  • Loading branch information
fedor-ivn committed Jun 20, 2024
1 parent 5d63e8a commit ce28a4b
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/abi/type_decoder.ex
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ defmodule ABI.TypeDecoder do
end

defp decode_type({:array, type, size}, data) do
types = List.duplicate(type, size)
types = Stream.repeatedly(fn -> type end) |> Stream.take(size)
{tuple, bytes} = decode_type({:tuple, types}, data)

{Tuple.to_list(tuple), bytes}
Expand Down Expand Up @@ -300,7 +300,7 @@ defmodule ABI.TypeDecoder do
<<_padding::binary-size(offset), rest_data::binary>> = full_data
{count, bytes} = decode_uint(rest_data, 256)

types = List.duplicate(type, count)
types = Stream.repeatedly(fn -> type end) |> Stream.take(count)

{tuple, _bytes} = decode_type({:tuple, types}, bytes)
{Tuple.to_list(tuple), rest_bytes}
Expand All @@ -310,7 +310,7 @@ defmodule ABI.TypeDecoder do
{offset, rest_bytes} = decode_uint(data, 256)
<<_padding::binary-size(offset), rest_data::binary>> = full_data

types = List.duplicate(type, size)
types = Stream.repeatedly(fn -> type end) |> Stream.take(size)

{tuple, _} = decode_type({:tuple, types}, rest_data)

Expand Down

0 comments on commit ce28a4b

Please sign in to comment.