string: rename _capacity field to _size

This commit is contained in:
anna 2021-07-16 13:35:32 +02:00
parent 7d0dd2d705
commit 6ab34d0893
Signed by: fef
GPG key ID: EC22E476DC2D3D84
4 changed files with 7 additions and 6 deletions

View file

@ -56,7 +56,8 @@ struct _neo_string {
/* The *amount of Unicode code points*, NOT amount of bytes */
NLEN_FIELD(_len);
NREF_FIELD;
usize _capacity;
/* physical size in bytes, including the four NUL terminators */
usize _size;
char *_data;
};
typedef struct _neo_string string;

View file

@ -25,7 +25,7 @@ static inline string *leftpad_unsafe(const string *s, usize len, nchar fillchr,
* but that's okay because if we don't even have enough memory for three
* extra bytes we are screwed anyway.
*/
usize size_now = s->_capacity;
usize size_now = s->_size;
usize size_after = size_now + (extra_chars * fillchr_size);
char *dest = nalloc(size_after, err);
catch(err) {

View file

@ -51,7 +51,7 @@ static string *nstr_unsafe(const char *restrict s, usize size_without_nul, error
}
str->_len = len;
str->_capacity = size_without_nul + 4;
str->_size = size_without_nul + 4;
nref_init(str, nstr_destroy);
memcpy(str->_data, s, size_without_nul);

View file

@ -23,10 +23,10 @@ int nstrcmp(const string *s1, const string *s2, error *err)
int ret;
usize maxbytes;
if (s1->_capacity > s2->_capacity)
maxbytes = s2->_capacity;
if (s1->_size > s2->_size)
maxbytes = s2->_size;
else
maxbytes = s1->_capacity;
maxbytes = s1->_size;
ret = strncmp(s1->_data, s2->_data, maxbytes);
neat(err);