mirror of
https://github.com/micropython/micropython.git
synced 2026-01-05 03:30:14 +01:00
py/vstr: Remove vstr.had_error flag and inline basic vstr functions.
The vstr.had_error flag was a relic from the very early days which assumed that the malloc functions (eg m_new, m_renew) returned NULL if they failed to allocate. But that's no longer the case: these functions will raise an exception if they fail. Since it was impossible for had_error to be set, this patch introduces no change in behaviour. An alternative option would be to change the malloc calls to the _maybe variants, which return NULL instead of raising, but then a lot of code will need to explicitly check if the vstr had an error and raise if it did. The code-size savings for this patch are, in bytes: bare-arm:188, minimal:456, unix(NDEBUG,x86-64):368, stmhal:228, esp8266:360.
This commit is contained in:
@@ -139,7 +139,6 @@ typedef struct _vstr_t {
|
||||
size_t alloc;
|
||||
size_t len;
|
||||
char *buf;
|
||||
bool had_error : 1;
|
||||
bool fixed_buf : 1;
|
||||
} vstr_t;
|
||||
|
||||
@@ -155,10 +154,9 @@ void vstr_clear(vstr_t *vstr);
|
||||
vstr_t *vstr_new(void);
|
||||
vstr_t *vstr_new_size(size_t alloc);
|
||||
void vstr_free(vstr_t *vstr);
|
||||
void vstr_reset(vstr_t *vstr);
|
||||
bool vstr_had_error(vstr_t *vstr);
|
||||
char *vstr_str(vstr_t *vstr);
|
||||
size_t vstr_len(vstr_t *vstr);
|
||||
static inline void vstr_reset(vstr_t *vstr) { vstr->len = 0; }
|
||||
static inline char *vstr_str(vstr_t *vstr) { return vstr->buf; }
|
||||
static inline size_t vstr_len(vstr_t *vstr) { return vstr->len; }
|
||||
void vstr_hint_size(vstr_t *vstr, size_t size);
|
||||
char *vstr_extend(vstr_t *vstr, size_t size);
|
||||
char *vstr_add_len(vstr_t *vstr, size_t len);
|
||||
|
||||
Reference in New Issue
Block a user