string: rename _capacity field to _size
This commit is contained in:
parent
7d0dd2d705
commit
6ab34d0893
4 changed files with 7 additions and 6 deletions
|
@ -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;
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue