Skip to content

Commit

Permalink
bam/record/codec/decoder/data/field/tag: Read tag as two bytes
Browse files Browse the repository at this point in the history
This reduces the overhead of `Buf::copy_to_slice`.
  • Loading branch information
zaeleus committed Jul 6, 2023
1 parent 723763e commit d36c0aa
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions noodles-bam/src/record/codec/decoder/data/field/tag.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{error, fmt};
use std::{error, fmt, mem};

use bytes::Buf;
use noodles_sam::record::data::field::{tag, Tag};
Expand Down Expand Up @@ -34,13 +34,13 @@ pub fn get_tag<B>(src: &mut B) -> Result<Tag, DecodeError>
where
B: Buf,
{
let mut buf = [0; 2];

if src.remaining() < buf.len() {
if src.remaining() < 2 * mem::size_of::<u8>() {
return Err(DecodeError::UnexpectedEof);
}

src.copy_to_slice(&mut buf);
let b0 = src.get_u8();
let b1 = src.get_u8();
let buf = [b0, b1];

Tag::try_from(buf).map_err(DecodeError::Invalid)
}
Expand Down

0 comments on commit d36c0aa

Please sign in to comment.