Browse Source

Cleanup

master
cancel 5 years ago
parent
commit
3c1603ee64
  1. 11
      thirdparty/sdd.c
  2. 14
      thirdparty/sdd.h

11
thirdparty/sdd.c

@ -51,7 +51,7 @@ typedef struct sdd_header {
#define SDD_HDR(s) ((sdd_header *)s - 1) #define SDD_HDR(s) ((sdd_header *)s - 1)
#if defined(__GNUC__) || defined(__clang__) #if defined(__GNUC__) || defined(__clang__)
#define SDD_NOINLINE __attribute__((noinline)) #define SDD_NOINLINE __attribute__((noinline, noclone))
#elif defined(_MSC_VER) #elif defined(_MSC_VER)
#define SDD_NOINLINE __declspec(noinline) #define SDD_NOINLINE __declspec(noinline)
#else #else
@ -104,16 +104,13 @@ sdd sdd_newlen(void const *init_str, size_t len) {
header->len = len; header->len = len;
header->cap = len; header->cap = len;
str = (char *)(header + 1); str = (char *)(header + 1);
if (len) memcpy(str, init_str, len);
memcpy(str, init_str, len);
str[len] = '\0'; str[len] = '\0';
return str; return str;
} }
sdd sdd_new(char const *str) { sdd sdd_new(char const *str) { return sdd_newlen(str, strlen(str)); }
size_t len = str ? strlen(str) : 0;
return sdd_newlen(str, len);
}
sdd sdd_newvprintf(char const *fmt, va_list ap) { sdd sdd_newvprintf(char const *fmt, va_list ap) {
return sdd_impl_catvprintf(NULL, fmt, ap); return sdd_impl_catvprintf(NULL, fmt, ap);
} }

14
thirdparty/sdd.h

@ -17,9 +17,9 @@
typedef char *sdd; typedef char *sdd;
sdd sdd_new(char const *str) SDD_ALLOCS; sdd sdd_new(char const *str) SDD_NONNULL() SDD_ALLOCS;
// ^- Create new with copy of null-terminated cstring. // ^- Create new with copy of null-terminated cstring.
sdd sdd_newlen(void const *str, size_t len) SDD_ALLOCS; sdd sdd_newlen(void const *str, size_t len) SDD_NONNULL() SDD_ALLOCS;
// ^- Same, but without calling strlen(). // ^- Same, but without calling strlen().
// Resulting new string will be null terminated. // Resulting new string will be null terminated.
sdd sdd_newcap(size_t cap) SDD_ALLOCS; sdd sdd_newcap(size_t cap) SDD_ALLOCS;
@ -42,9 +42,9 @@ size_t sdd_cap(sdd const str) SDD_NONNULL();
size_t sdd_avail(sdd const str) SDD_NONNULL(); size_t sdd_avail(sdd const str) SDD_NONNULL();
// ^- cap - len // ^- cap - len
sdd sdd_cat(sdd str, char const *other) SDD_NONNULL() SDD_RESULT; sdd sdd_cat(sdd str, char const *restrict other) SDD_NONNULL() SDD_RESULT;
sdd sdd_catlen(sdd str, char const *other, size_t len) SDD_RESULT; sdd sdd_catlen(sdd str, char const *restrict other, size_t len) SDD_RESULT;
sdd sdd_catsdd(sdd str, sdd const other) SDD_RESULT; sdd sdd_catsdd(sdd str, sdd restrict const other) SDD_RESULT;
sdd sdd_catvprintf(sdd str, char const *fmt, va_list ap) SDD_RESULT; sdd sdd_catvprintf(sdd str, char const *fmt, va_list ap) SDD_RESULT;
sdd sdd_catprintf(sdd str, char const *fmt, ...) SDD_PRINTF(2, 3) SDD_RESULT; sdd sdd_catprintf(sdd str, char const *fmt, ...) SDD_PRINTF(2, 3) SDD_RESULT;
@ -54,9 +54,9 @@ sdd sdd_makeroomfor(sdd str, size_t add_len) SDD_NONNULL() SDD_RESULT;
void sdd_pokelen(sdd str, size_t len) SDD_NONNULL(); void sdd_pokelen(sdd str, size_t len) SDD_NONNULL();
// ^- Manually update length field. Doesn't do anything else for you. // ^- Manually update length field. Doesn't do anything else for you.
bool sdd_equal(sdd const lhs, sdd const rhs) SDD_NONULL(); bool sdd_equal(sdd const lhs, sdd const rhs) SDD_NONNULL();
sdd sdd_trim(sdd str, char const *cut_set) SDD_RESULT SDD_NONULL(); sdd sdd_trim(sdd str, char const *cut_set) SDD_RESULT SDD_NONNULL();
size_t sdd_totalmemused(sdd const str); size_t sdd_totalmemused(sdd const str);

Loading…
Cancel
Save