Skip to content

Commit

Permalink
Inline sdslen and sdsavail (thanks to @bitbckt)
Browse files Browse the repository at this point in the history
  • Loading branch information
pietern committed Apr 19, 2011
1 parent d5b18b5 commit cd7063e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
12 changes: 1 addition & 11 deletions sds.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@

#define SDS_ABORT_ON_OOM

#include "sds.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "sds.h"

static void sdsOomAbort(void) {
fprintf(stderr,"SDS: Out Of Memory (SDS_ABORT_ON_OOM defined)\n");
Expand Down Expand Up @@ -69,11 +69,6 @@ sds sdsnew(const char *init) {
return sdsnewlen(init, initlen);
}

size_t sdslen(const sds s) {
struct sdshdr *sh = (void*) (s-(sizeof(struct sdshdr)));
return sh->len;
}

sds sdsdup(const sds s) {
return sdsnewlen(s, sdslen(s));
}
Expand All @@ -83,11 +78,6 @@ void sdsfree(sds s) {
free(s-sizeof(struct sdshdr));
}

size_t sdsavail(sds s) {
struct sdshdr *sh = (void*) (s-(sizeof(struct sdshdr)));
return sh->free;
}

void sdsupdatelen(sds s) {
struct sdshdr *sh = (void*) (s-(sizeof(struct sdshdr)));
int reallen = strlen(s);
Expand Down
10 changes: 10 additions & 0 deletions sds.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@ struct sdshdr {
char buf[];
};

static inline size_t sdslen(const sds s) {
struct sdshdr *sh = (void*)(s-(sizeof(struct sdshdr)));
return sh->len;
}

static inline size_t sdsavail(const sds s) {
struct sdshdr *sh = (void*)(s-(sizeof(struct sdshdr)));
return sh->free;
}

sds sdsnewlen(const void *init, size_t initlen);
sds sdsnew(const char *init);
sds sdsempty(void);
Expand Down

0 comments on commit cd7063e

Please sign in to comment.