Skip to content

Commit

Permalink
Move the bulk of ks_resize() to a non-inlined helper function
Browse files Browse the repository at this point in the history
  • Loading branch information
jmarshall authored and daviesrob committed Mar 18, 2020
1 parent ba8d1a1 commit 04b71e6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
12 changes: 3 additions & 9 deletions htslib/kstring.h
Expand Up @@ -144,15 +144,9 @@ static inline void ks_initialize(kstring_t *s)
/// Resize a kstring to a given capacity
static inline int ks_resize(kstring_t *s, size_t size)
{
if (s->m < size) {
char *tmp;
kroundup_size_t(size);
tmp = (char*)realloc(s->s, size);
if (!tmp && size)
return -1;
s->s = tmp;
s->m = size;
}
extern HTSLIB_EXPORT int ks_resize2(kstring_t *s, size_t size);

if (s->m < size) return ks_resize2(s, size);
return 0;
}

Expand Down
13 changes: 13 additions & 0 deletions kstring.c
Expand Up @@ -35,6 +35,19 @@
#include <math.h>
#include "htslib/kstring.h"

HTSLIB_EXPORT
int ks_resize2(kstring_t *s, size_t size)
{
char *tmp;
kroundup_size_t(size);
tmp = (char*)realloc(s->s, size);
if (!tmp && size)
return -1;
s->s = tmp;
s->m = size;
return 0;
}

int kputd(double d, kstring_t *s) {
int len = 0;
char buf[21], *cp = buf+20, *ep;
Expand Down

0 comments on commit 04b71e6

Please sign in to comment.