Skip to content

Commit

Permalink
csi/io/reader/index/header/reference_sequence_names: Use memchr to fi…
Browse files Browse the repository at this point in the history
…nd NUL terminators
  • Loading branch information
zaeleus committed Nov 5, 2024
1 parent 1569d19 commit ff02a57
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions noodles-csi/src/io/reader/index/header/reference_sequence_names.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::{
num,
};

use bstr::BString;
use bstr::{BString, ByteSlice};
use byteorder::{LittleEndian, ReadBytesExt};

use crate::binning_index::index::header::ReferenceSequenceNames;
Expand Down Expand Up @@ -79,19 +79,17 @@ where
break;
}

let len = match src.iter().position(|&b| b == NUL) {
Some(i) => {
let name = &src[..i];
let Some(i) = src.as_bstr().find_byte(NUL) else {
return Err(ReadError::ExpectedEof);
};

if !names.insert(name.into()) {
return Err(ReadError::DuplicateName(name.into()));
}
let name = &src[..i];

i + 1
}
None => return Err(ReadError::ExpectedEof),
};
if !names.insert(name.into()) {
return Err(ReadError::DuplicateName(name.into()));
}

let len = i + 1;
reader.consume(len);
}

Expand Down

0 comments on commit ff02a57

Please sign in to comment.