Skip to content
Snippets Groups Projects
Commit a4c8a1ff authored by Paul Sokolovsky's avatar Paul Sokolovsky
Browse files

extmod/moduos_dupterm: Reuse dupterm_arr_obj for write operations.

Instead of allocating new array object header again and again, causing
memory fragmentation.
parent ec7fe925
No related branches found
No related tags found
No related merge requests found
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#include "py/nlr.h" #include "py/nlr.h"
#include "py/runtime.h" #include "py/runtime.h"
#include "py/objtuple.h" #include "py/objtuple.h"
#include "py/objarray.h"
#include "py/stream.h" #include "py/stream.h"
#if MICROPY_PY_OS_DUPTERM #if MICROPY_PY_OS_DUPTERM
...@@ -51,8 +52,16 @@ void mp_uos_dupterm_tx_strn(const char *str, size_t len) { ...@@ -51,8 +52,16 @@ void mp_uos_dupterm_tx_strn(const char *str, size_t len) {
if (nlr_push(&nlr) == 0) { if (nlr_push(&nlr) == 0) {
mp_obj_t write_m[3]; mp_obj_t write_m[3];
mp_load_method(MP_STATE_PORT(term_obj), MP_QSTR_write, write_m); mp_load_method(MP_STATE_PORT(term_obj), MP_QSTR_write, write_m);
write_m[2] = mp_obj_new_bytearray_by_ref(len, (char*)str);
mp_obj_array_t *arr = MP_OBJ_TO_PTR(MP_STATE_PORT(dupterm_arr_obj));
void *org_items = arr->items;
arr->items = (void*)str;
arr->len = len;
write_m[2] = MP_STATE_PORT(dupterm_arr_obj);
mp_call_method_n_kw(1, 0, write_m); mp_call_method_n_kw(1, 0, write_m);
arr = MP_OBJ_TO_PTR(MP_STATE_PORT(dupterm_arr_obj));
arr->items = org_items;
arr->len = 1;
nlr_pop(); nlr_pop();
} else { } else {
mp_uos_deactivate("dupterm: Exception in write() method, deactivating: ", nlr.ret_val); mp_uos_deactivate("dupterm: Exception in write() method, deactivating: ", nlr.ret_val);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment