Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Speed up faidx. #1797

Merged
merged 1 commit into from
Jul 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion faidx.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,29 @@ DEALINGS IN THE SOFTWARE. */
#include "htslib/kstring.h"
#include "hts_internal.h"

// Faster isgraph; assumes ASCII
static inline int isgraph_(unsigned char c) {
return c > ' ' && c <= '~';
}

#ifdef isgraph
# undef isgraph
#endif
#define isgraph isgraph_

// An optimised bgzf_getc.
// We could consider moving this to bgzf.h, but our own code uses it here only.
static inline int bgzf_getc_(BGZF *fp) {
if (fp->block_offset+1 < fp->block_length) {
int c = ((unsigned char*)fp->uncompressed_block)[fp->block_offset++];
fp->uncompressed_address++;
return c;
}

return bgzf_getc(fp);
}
#define bgzf_getc bgzf_getc_

typedef struct {
int id; // faidx_t->name[id] is for this struct.
uint32_t line_len, line_blen;
Expand Down Expand Up @@ -727,7 +750,8 @@ static char *fai_retrieve(const faidx_t *fai, const faidx1_t *val,
return NULL;
}

while ( l < end - beg && (c=bgzf_getc(fai->bgzf))>=0 )
BGZF *fp = fai->bgzf;
while ( l < end - beg && (c=bgzf_getc(fp))>=0 )
if (isgraph(c)) s[l++] = c;
if (c < 0) {
hts_log_error("Failed to retrieve block: %s",
Expand Down