summaryrefslogtreecommitdiff
path: root/py/objexcept.c
diff options
context:
space:
mode:
authorJeff Epler <jepler@gmail.com>2020-05-28 07:40:56 -0500
committerJeff Epler <jepler@gmail.com>2020-05-28 08:36:08 -0500
commitfe3e8d1589e54de999cccc775f269a39443c82d6 (patch)
treecbddbbf82646575a90e86a7dc5d1185bd2651c0c /py/objexcept.c
parent0db8b888d3e1928ae2a81f0ec9d3834a69989ed4 (diff)
string compression: save a few bits per string
Length was stored as a 16-bit number always. Most translations have a max length far less. For example, US English translation lengths always fit in just 8 bits. probably all languages fit in 9 bits. This also has the side effect of reducing the alignment of compressed_string_t from 2 bytes to 1. testing performed: ran in german and english on pyruler, printed messages looked right. Firmware size, en_US Before: 3044 bytes free in flash After: 3408 bytes free in flash Firmware size, de_DE (with #2967 merged to restore translations) Before: 1236 bytes free in flash After: 1600 bytes free in flash
Diffstat (limited to 'py/objexcept.c')
-rw-r--r--py/objexcept.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/py/objexcept.c b/py/objexcept.c
index b7a536c5e..796be122f 100644
--- a/py/objexcept.c
+++ b/py/objexcept.c
@@ -400,7 +400,7 @@ mp_obj_t mp_obj_new_exception_msg_vlist(const mp_obj_type_t *exc_type, const com
// Try to allocate memory for the message
mp_obj_str_t *o_str = m_new_obj_maybe(mp_obj_str_t);
- size_t o_str_alloc = fmt->length + 1;
+ size_t o_str_alloc = decompress_length(fmt);
byte *o_str_buf = m_new_maybe(byte, o_str_alloc);
bool used_emg_buf = false;
@@ -433,7 +433,7 @@ mp_obj_t mp_obj_new_exception_msg_vlist(const mp_obj_type_t *exc_type, const com
// We have some memory to format the string
struct _exc_printer_t exc_pr = {!used_emg_buf, o_str_alloc, 0, o_str_buf};
mp_print_t print = {&exc_pr, exc_add_strn};
- char fmt_decompressed[fmt->length];
+ char fmt_decompressed[decompress_length(fmt)];
decompress(fmt, fmt_decompressed);
mp_vprintf(&print, fmt_decompressed, ap);
exc_pr.buf[exc_pr.len] = '\0';