Skip to content

Commit

Permalink
Merge pull request #18583 from JuliaLang/jn/faster-deser-array
Browse files Browse the repository at this point in the history
small perf enhancement for deserialize of Arrays
  • Loading branch information
vtjnash authored Sep 20, 2016
2 parents 47fbd9c + 636f1e4 commit aca3311
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions base/serialize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -170,14 +170,14 @@ function serialize_array_data(s::IO, a)
count = 1
for i = 2:length(a)
if a[i] != last || count == 127
write(s, UInt8((UInt8(last)<<7) | count))
write(s, UInt8((UInt8(last) << 7) | count))
last = a[i]
count = 1
else
count += 1
end
end
write(s, UInt8((UInt8(last)<<7) | count))
write(s, UInt8((UInt8(last) << 7) | count))
else
write(s, a)
end
Expand Down Expand Up @@ -662,40 +662,42 @@ end

function deserialize_array(s::AbstractSerializer)
d1 = deserialize(s)
if isa(d1,Type)
if isa(d1, Type)
elty = d1
d1 = deserialize(s)
else
elty = UInt8
end
if isa(d1,Integer)
if isa(d1, Integer)
if elty !== Bool && isbits(elty)
return read!(s.io, Array{elty}(d1))
a = Array{elty, 1}(d1)
return read!(s.io, a)
end
dims = (Int(d1),)
else
dims = convert(Dims, d1)::Dims
end
if isbits(elty)
n = prod(dims)::Int
if elty === Bool && n>0
A = Array{Bool}(dims)
if elty === Bool && n > 0
A = Array{Bool, length(dims)}(dims)
i = 1
while i <= n
b = read(s.io, UInt8)::UInt8
v = (b>>7) != 0
count = b&0x7f
nxt = i+count
v = (b >> 7) != 0
count = b & 0x7f
nxt = i + count
while i < nxt
A[i] = v; i+=1
A[i] = v
i += 1
end
end
else
A = read(s.io, elty, dims)
end
return A
end
A = Array{elty}(dims)
A = Array{elty, length(dims)}(dims)
deserialize_cycle(s, A)
for i = eachindex(A)
tag = Int32(read(s.io, UInt8)::UInt8)
Expand Down

0 comments on commit aca3311

Please sign in to comment.