From b0069d6f27e19ab81f03024f56273c8897e1afdd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ciar=C3=A1n=20O=27Mara?= Date: Sun, 2 Feb 2020 21:29:20 +1100 Subject: [PATCH] Preallocate --- src/bam/reader.jl | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/bam/reader.jl b/src/bam/reader.jl index 9ec5d0d..0fabb8f 100644 --- a/src/bam/reader.jl +++ b/src/bam/reader.jl @@ -87,7 +87,7 @@ function init_bam_reader(input::BGZFStreams.BGZFStream) A = read(input, UInt8) M = read(input, UInt8) x = read(input, UInt8) - + if B != UInt8('B') || A != UInt8('A') || M != UInt8('M') || x != 0x01 error("input was not a valid BAM file") end @@ -97,16 +97,16 @@ function init_bam_reader(input::BGZFStreams.BGZFStream) samreader = SAM.Reader(IOBuffer(read(input, textlen))) # reference sequences - refseqnames = String[] - refseqlens = Int[] n_refs = read(input, Int32) - for _ in 1:n_refs + refseqnames = Vector{String}(undef, n_refs) + refseqlens = Vector{Int}(undef, n_refs) + @inbounds for i in 1:n_refs namelen = read(input, Int32) data = read(input, namelen) seqname = unsafe_string(pointer(data)) seqlen = read(input, Int32) - push!(refseqnames, seqname) - push!(refseqlens, seqlen) + refseqnames[i] = seqname + refseqlens[i] = seqlen end voffset = isa(input.io, Base.AbstractPipe) ?