py: Remove mp_obj_str_builder and use vstr instead.

With this patch str/bytes construction is streamlined.  Always use a
vstr to build a str/bytes object.  If the size is known beforehand then
use vstr_init_len to allocate only required memory.  Otherwise use
vstr_init and the vstr will grow as needed.  Then use
mp_obj_new_str_from_vstr to create a str/bytes object using the vstr
memory.

Saves code ROM: 68 bytes on stmhal, 108 bytes on bare-arm, and 336 bytes
on unix x64.
This commit is contained in:
Damien George
2015-01-21 22:48:37 +00:00
parent 0b9ee86133
commit 05005f679e
18 changed files with 130 additions and 143 deletions

View File

@@ -52,6 +52,11 @@ void vstr_init(vstr_t *vstr, size_t alloc) {
vstr->fixed_buf = false;
}
void vstr_init_len(vstr_t *vstr, size_t len) {
vstr_init(vstr, len + 1);
vstr_add_len(vstr, len);
}
void vstr_init_fixed_buf(vstr_t *vstr, size_t alloc, char *buf) {
assert(alloc > 0); // need at least room for the null byte
vstr->alloc = alloc;