summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPieter Noordhuis <pcnoordhuis@gmail.com>2011-04-19 22:59:26 +0200
committerPieter Noordhuis <pcnoordhuis@gmail.com>2011-04-19 22:59:26 +0200
commitcd7063e85b3f7b32f7e37585615d4180a1188cba (patch)
tree4aa3d49790379fe181fd37a69f7a8da6bacf2698
parentd5b18b5d2878255440b9f8f73f4613190d3376b0 (diff)
Inline sdslen and sdsavail (thanks to @bitbckt)
-rw-r--r--sds.c12
-rw-r--r--sds.h10
2 files changed, 11 insertions, 11 deletions
diff --git a/sds.c b/sds.c
index f05b107..2bd5a81 100644
--- a/sds.c
+++ b/sds.c
@@ -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");
@@ -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));
}
@@ -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);
diff --git a/sds.h b/sds.h
index eb41eb7..94f5871 100644
--- a/sds.h
+++ b/sds.h
@@ -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);