diff options
| author | Tyge Løvset <[email protected]> | 2020-03-29 20:19:34 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2020-03-29 20:19:34 +0200 |
| commit | a8e178e11e4955306d32e4c48be348d50dbcb3df (patch) | |
| tree | f4ea5d741323feeefd95671bad301ced5e113357 /c_lib/cstring.h | |
| parent | 124f1eaaa8c7e5dafad8f6ba1898b09b38bac9dc (diff) | |
| download | STC-modified-a8e178e11e4955306d32e4c48be348d50dbcb3df.tar.gz STC-modified-a8e178e11e4955306d32e4c48be348d50dbcb3df.zip | |
Add files via upload
Diffstat (limited to 'c_lib/cstring.h')
| -rw-r--r-- | c_lib/cstring.h | 12 |
1 files changed, 4 insertions, 8 deletions
diff --git a/c_lib/cstring.h b/c_lib/cstring.h index 92cb1555..d0719cb6 100644 --- a/c_lib/cstring.h +++ b/c_lib/cstring.h @@ -38,12 +38,13 @@ typedef struct CString { static size_t _cstring_null_rep[] = {0, 0, 0};
#define _cstring_rep(cs) (((size_t *) (cs).str) - 2)
-#define cstring_initializer {(char* ) (_cstring_null_rep + 2)}
#define cstring_size(cs) ((size_t) _cstring_rep(cs)[0])
#define cstring_capacity(cs) ((size_t) _cstring_rep(cs)[1])
#define cstring_npos c_npos
+static const CString cstring_init = {(char* ) &_cstring_null_rep[2]};
+
static inline void cstring_reserve(CString* self, size_t cap) {
size_t len = cstring_size(*self), oldcap = cstring_capacity(*self);
if (cap > oldcap) {
@@ -60,13 +61,8 @@ static inline void cstring_destroy(CString* self) { }
}
-static inline CString cstring_init(void) {
- CString cs = cstring_initializer;
- return cs;
-}
-
static inline CString cstring_makeN(const char* str, size_t len) {
- CString cs = cstring_initializer;
+ CString cs = cstring_init;
if (len) {
cstring_reserve(&cs, len);
memcpy(cs.str, str, len);
@@ -84,7 +80,7 @@ static inline CString cstring_makeCopy(CString cs) { }
static inline void cstring_clear(CString* self) {
- CString cs = cstring_initializer;
+ CString cs = cstring_init;
cstring_destroy(self);
*self = cs;
}
|
