Skip to content

Commit

Permalink
More review commits
Browse files Browse the repository at this point in the history
  • Loading branch information
jkbonfield committed Aug 7, 2023
1 parent 59d14e9 commit e1bbc3f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 23 deletions.
10 changes: 0 additions & 10 deletions htslib/vcf.h
Original file line number Diff line number Diff line change
Expand Up @@ -1562,16 +1562,6 @@ static inline int bcf_enc_inttype(long x)
return BCF_BT_INT32;
}

// INTERNAL - not to be assumed to be a part of public API
// As per bcf_enc_size but kstring is already guaranteed to be big enough
// and with size == 1.
static inline void bcf_enc_size1_(kstring_t *s, int type)
{
uint8_t *p = (uint8_t *)s->s + s->l;
*p++ = (1<<4) | type;
s->l++;
}

static inline int bcf_enc_int1(kstring_t *s, int32_t x)
{
if (ks_resize(s, s->l + 5) < 0)
Expand Down
30 changes: 17 additions & 13 deletions vcf.c
Original file line number Diff line number Diff line change
Expand Up @@ -2487,9 +2487,11 @@ int bcf_enc_vint(kstring_t *s, int n, int32_t *a, int wsize)
{
int32_t max = INT32_MIN, min = INT32_MAX;
int i;
if (n <= 0) bcf_enc_size(s, 0, BCF_BT_NULL);
else if (n == 1) bcf_enc_int1(s, a[0]);
else {
if (n <= 0) {
return bcf_enc_size(s, 0, BCF_BT_NULL);
} else if (n == 1) {
return bcf_enc_int1(s, a[0]);
} else {
if (wsize <= 0) wsize = n;

// Equivalent to:
Expand Down Expand Up @@ -2528,9 +2530,9 @@ int bcf_enc_vint(kstring_t *s, int n, int32_t *a, int wsize)
}

if (max <= BCF_MAX_BT_INT8 && min >= BCF_MIN_BT_INT8) {
bcf_enc_size(s, wsize, BCF_BT_INT8);

ks_resize(s, s->l + n);
if (bcf_enc_size(s, wsize, BCF_BT_INT8) < 0 ||
ks_resize(s, s->l + n) < 0)
return -1;
uint8_t *p = (uint8_t *) s->s + s->l;
for (i = 0; i < n; ++i, p++) {
if ( a[i]==bcf_int32_vector_end ) *p = bcf_int8_vector_end;
Expand All @@ -2540,8 +2542,9 @@ int bcf_enc_vint(kstring_t *s, int n, int32_t *a, int wsize)
s->l += n;
} else if (max <= BCF_MAX_BT_INT16 && min >= BCF_MIN_BT_INT16) {
uint8_t *p;
bcf_enc_size(s, wsize, BCF_BT_INT16);
ks_resize(s, s->l + n * sizeof(int16_t));
if (bcf_enc_size(s, wsize, BCF_BT_INT16) < 0 ||
ks_resize(s, s->l + n * sizeof(int16_t)) < 0)
return -1;
p = (uint8_t *) s->s + s->l;
for (i = 0; i < n; ++i)
{
Expand All @@ -2555,8 +2558,9 @@ int bcf_enc_vint(kstring_t *s, int n, int32_t *a, int wsize)
s->l += n * sizeof(int16_t);
} else {
uint8_t *p;
bcf_enc_size(s, wsize, BCF_BT_INT32);
ks_resize(s, s->l + n * sizeof(int32_t));
if (bcf_enc_size(s, wsize, BCF_BT_INT32) < 0 ||
ks_resize(s, s->l + n * sizeof(int32_t)) < 0)
return -1;
p = (uint8_t *) s->s + s->l;
for (i = 0; i < n; ++i) {
i32_to_le(a[i], p);
Expand All @@ -2566,7 +2570,7 @@ int bcf_enc_vint(kstring_t *s, int n, int32_t *a, int wsize)
}
}

return 0; // FIXME: check for errs in this function
return 0;
}

#ifdef VCF_ALLOW_INT64
Expand Down Expand Up @@ -2932,12 +2936,12 @@ static int vcf_parse_format_alloc4(kstring_t *s, const bcf_hdr_t *h, bcf1_t *v,
return 0;
}

// fill the sample fields; at beginning of the loop
// Fill the sample fields
static int vcf_parse_format_fill5(kstring_t *s, const bcf_hdr_t *h, bcf1_t *v,
const char *p, const char *q, fmt_aux_t *fmt) {
static int extreme_val_warned = 0;
int n_sample_ori = -1;
// t points to the first char of a format
// At beginning of the loop t points to the first char of a format
const char *t = q + 1;
int m = 0; // m: sample id
const int nsamples = bcf_hdr_nsamples(h);
Expand Down

0 comments on commit e1bbc3f

Please sign in to comment.