summaryrefslogtreecommitdiff
path: root/supervisor
diff options
context:
space:
mode:
authorScott Shawcroft <scott@adafruit.com>2020-09-10 11:44:56 -0700
committerGitHub <noreply@github.com>2020-09-10 11:44:56 -0700
commit1ba28b3edc65c8c739cc25c9a317c8b6c5a2a510 (patch)
tree267403fa31d63ad533c287b541a41153ce8816ae /supervisor
parent683462c1b15055e20da55c40243e314d660f803a (diff)
parent0eee93729a3074461c4907f03deb803c2f35a6fe (diff)
Merge pull request #3370 from jepler/compression-bigrams
add bigram compression to makeqstrdata (save ~100 bytes on trinket m0 de_DE)
Diffstat (limited to 'supervisor')
-rw-r--r--supervisor/shared/translate.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/supervisor/shared/translate.c b/supervisor/shared/translate.c
index 606f8fa91..5cd7b8dd8 100644
--- a/supervisor/shared/translate.c
+++ b/supervisor/shared/translate.c
@@ -34,6 +34,7 @@
#include "genhdr/compression.generated.h"
#endif
+#include "py/misc.h"
#include "supervisor/serial.h"
void serial_write_compressed(const compressed_string_t* compressed) {
@@ -46,13 +47,20 @@ STATIC int put_utf8(char *buf, int u) {
if(u <= 0x7f) {
*buf = u;
return 1;
+ } else if(bigram_start <= u && u <= bigram_end) {
+ int n = (u - 0x80) * 2;
+ // (note that at present, entries in the bigrams table are
+ // guaranteed not to represent bigrams themselves, so this adds
+ // at most 1 level of recursive call
+ int ret = put_utf8(buf, bigrams[n]);
+ return ret + put_utf8(buf + ret, bigrams[n+1]);
} else if(u <= 0x07ff) {
*buf++ = 0b11000000 | (u >> 6);
*buf = 0b10000000 | (u & 0b00111111);
return 2;
- } else { // u <= 0xffff)
- *buf++ = 0b11000000 | (u >> 12);
- *buf = 0b10000000 | ((u >> 6) & 0b00111111);
+ } else { // u <= 0xffff
+ *buf++ = 0b11100000 | (u >> 12);
+ *buf++ = 0b10000000 | ((u >> 6) & 0b00111111);
*buf = 0b10000000 | (u & 0b00111111);
return 3;
}