Skip to content

Commit 64035a5

Browse files
committed
docs: improve preallocation docstrings
1 parent 09ec6ec commit 64035a5

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

src/NodePreallocation.jl

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,27 @@ using ..NodeModule:
88
branch_copy,
99
set_node!
1010

11+
"""
12+
allocate_container(prototype::AbstractExpressionNode, n=nothing)
13+
14+
Preallocate an array of `n` empty nodes matching the type of `prototype`.
15+
If `n` is not provided, it will be computed from `length(prototype)`.
16+
17+
A given return value of this will be passed to `copy_into!` as the first argument,
18+
so it should be compatible.
19+
"""
20+
function allocate_container(
21+
prototype::N, n::Union{Nothing,Integer}=nothing
22+
) where {T,N<:AbstractExpressionNode{T}}
23+
num_nodes = @something(n, length(prototype))
24+
return N[with_type_parameters(N, T)() for _ in 1:num_nodes]
25+
end
26+
1127
"""
1228
copy_into!(dest::AbstractArray{N}, src::N) where {N<:AbstractExpressionNode}
1329
14-
Copy a node, recursively copying all children nodes, in-place to an
15-
array of pre-allocated nodes. This should result in no extra allocations.
30+
Copy a node, recursively copying all children nodes, in-place to a preallocated container.
31+
This should result in no extra allocations.
1632
"""
1733
function copy_into!(
1834
dest::AbstractArray{N}, src::N; ref::Union{Nothing,Base.RefValue{<:Integer}}=nothing
@@ -48,20 +64,5 @@ function branch_copy_into!(
4864
return dest
4965
end
5066

51-
"""
52-
allocate_container(prototype::AbstractExpressionNode, n=nothing)
53-
54-
Preallocate an array of `n` empty nodes matching the type of `prototype`.
55-
If `n` is not provided, it will be computed from `length(prototype)`.
56-
57-
A given return value of this will be passed to `copy_into!` as the first argument,
58-
so it should be compatible.
59-
"""
60-
function allocate_container(
61-
prototype::N, n::Union{Nothing,Integer}=nothing
62-
) where {T,N<:AbstractExpressionNode{T}}
63-
num_nodes = @something(n, length(prototype))
64-
return N[with_type_parameters(N, T)() for _ in 1:num_nodes]
65-
end
6667

6768
end

0 commit comments

Comments
 (0)