@@ -8,6 +8,9 @@ struct SummarySize
88    chargeall:: Any 
99end 
1010
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+ 
1114""" 
1215    Base.summarysize(obj; exclude=Union{...}, chargeall=Union{...}) -> Int 
1316
@@ -26,7 +29,7 @@ julia> Base.summarysize(1.0)
26298 
2730
2831julia> Base.summarysize(Ref(rand(100))) 
29- 864 
32+ 848 
3033
3134julia> sizeof(Ref(rand(100))) 
32358 
@@ -50,15 +53,28 @@ function summarysize(obj;
5053                val =  x[i]
5154            end 
5255        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 
5673            end 
5774        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)
6278            end 
6379        end 
6480        if  nf >  i
8298    #  and so is somewhat approximate.
8399    key =  ccall (:jl_value_ptr , Ptr{Cvoid}, (Any,), obj)
84100    haskey (ss. seen, key) ?  (return  0 ) :  (ss. seen[key] =  true )
85-     if  nfields ( obj) >  0 
101+     if  datatype_npointers ( typeof ( obj) ) >  0 
86102        push! (ss. frontier_x, obj)
87103        push! (ss. frontier_i, 1 )
88104    end 
0 commit comments