@@ -8,11 +8,27 @@ using ..NodeModule:
8
8
branch_copy,
9
9
set_node!
10
10
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
+
11
27
"""
12
28
copy_into!(dest::AbstractArray{N}, src::N) where {N<:AbstractExpressionNode}
13
29
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.
16
32
"""
17
33
function copy_into! (
18
34
dest:: AbstractArray{N} , src:: N ; ref:: Union{Nothing,Base.RefValue{<:Integer}} = nothing
@@ -48,20 +64,5 @@ function branch_copy_into!(
48
64
return dest
49
65
end
50
66
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
66
67
67
68
end
0 commit comments