@@ -8,6 +8,9 @@ struct SummarySize
8
8
chargeall:: Any
9
9
end
10
10
11
+ nth_pointer_isdefined (obj, i:: Int ) = ccall (:jl_nth_pointer_isdefined , Cint, (Any, Csize_t), obj, i- 1 ) != 0
12
+ get_nth_pointer (obj, i:: Int ) = ccall (:jl_get_nth_pointer , Any, (Any, Csize_t), obj, i- 1 )
13
+
11
14
"""
12
15
Base.summarysize(obj; exclude=Union{...}, chargeall=Union{...}) -> Int
13
16
@@ -50,15 +53,28 @@ function summarysize(obj;
50
53
val = x[i]
51
54
end
52
55
elseif isa (x, GenericMemory)
53
- nf = length (x)
54
- if @inbounds @inline isassigned (x, i)
55
- val = x[i]
56
+ T = eltype (x)
57
+ if Base. allocatedinline (T)
58
+ np = datatype_npointers (T)
59
+ nf = length (x) * np
60
+ idx = (i- 1 ) ÷ np + 1
61
+ if @inbounds @inline isassigned (x, idx)
62
+ elt = x[idx]
63
+ p = (i- 1 ) % np + 1
64
+ if nth_pointer_isdefined (elt, p)
65
+ val = get_nth_pointer (elt, p)
66
+ end
67
+ end
68
+ else
69
+ nf = length (x)
70
+ if @inbounds @inline isassigned (x, i)
71
+ val = x[i]
72
+ end
56
73
end
57
74
else
58
- nf = nfields (x)
59
- ft = typeof (x). types
60
- if ! isbitstype (ft[i]) && isdefined (x, i)
61
- val = getfield (x, i)
75
+ nf = datatype_npointers (typeof (x))
76
+ if nth_pointer_isdefined (x, i)
77
+ val = get_nth_pointer (x, i)
62
78
end
63
79
end
64
80
if nf > i
82
98
# and so is somewhat approximate.
83
99
key = ccall (:jl_value_ptr , Ptr{Cvoid}, (Any,), obj)
84
100
haskey (ss. seen, key) ? (return 0 ) : (ss. seen[key] = true )
85
- if nfields ( obj) > 0
101
+ if datatype_npointers ( typeof ( obj) ) > 0
86
102
push! (ss. frontier_x, obj)
87
103
push! (ss. frontier_i, 1 )
88
104
end
0 commit comments