From 7d1df2953125d96db7cf89bfc3d6048f77263c2e Mon Sep 17 00:00:00 2001 From: Valentyn Bezshapkin <61702053+valentynbez@users.noreply.github.com> Date: Thu, 28 Sep 2023 09:27:38 +0200 Subject: [PATCH] Backport htslib/kseq.h parsing performance improvement (PR #1227) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Apply the main part of PR samtools/htslib#1674. Pysam does use kseq itself, so it is worth applying this now without waiting for the next HTSlib release to be imported. Co-Authored-By: Fabian Klötzl --- htslib/htslib/kseq.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htslib/htslib/kseq.h b/htslib/htslib/kseq.h index ea887f14..92855d0e 100644 --- a/htslib/htslib/kseq.h +++ b/htslib/htslib/kseq.h @@ -110,8 +110,8 @@ } else break; \ } \ if (delimiter == KS_SEP_LINE) { \ - for (i = ks->begin; i < ks->end; ++i) \ - if (ks->buf[i] == '\n') break; \ + unsigned char *sep = memchr(ks->buf + ks->begin, '\n', ks->end - ks->begin); \ + i = sep != NULL ? sep - ks->buf : ks->end; \ } else if (delimiter > KS_SEP_MAX) { \ for (i = ks->begin; i < ks->end; ++i) \ if (ks->buf[i] == delimiter) break; \