summaryrefslogtreecommitdiff
path: root/wasp/fonts
diff options
context:
space:
mode:
authorDaniel Thompson <daniel@redfelineninja.org.uk>2020-03-09 21:33:29 (GMT)
committerDaniel Thompson <daniel@redfelineninja.org.uk>2020-03-09 21:33:29 (GMT)
commit3ded49c5eff3edd9993c9ee88a96661a459b866a (patch)
tree9a0b5b1f914085796b5c6db5edbac57b8410c134 /wasp/fonts
parent820764081ec4327cdc294d52fa6a1d441f220d75 (diff)
fonts: sans24: Minor refactor to reduce memory allocation
This is a useful but modest optimization (maybe 3% in string rendering.
Diffstat (limited to 'wasp/fonts')
-rw-r--r--wasp/fonts/sans24.py9
1 files changed, 5 insertions, 4 deletions
diff --git a/wasp/fonts/sans24.py b/wasp/fonts/sans24.py
index 2fdb6f2..5cbe3b4 100644
--- a/wasp/fonts/sans24.py
+++ b/wasp/fonts/sans24.py
@@ -355,14 +355,15 @@ b'\x50\x13'
_mvfont = memoryview(_font)
_mvi = memoryview(_index)
-ifb = lambda l : l[0] | (l[1] << 8)
def get_ch(ch):
+ mvi = _mvi
+ mvfont = _mvfont
+
oc = ord(ch)
ioff = 2 * (oc - 32 + 1) if oc >= 32 and oc <= 126 else 0
- doff = ifb(_mvi[ioff : ])
- width = ifb(_mvfont[doff : ])
+ doff = mvi[ioff] | (mvi[ioff+1] << 8)
+ width = mvfont[doff] | (mvfont[doff+1] << 8)
next_offs = doff + 2 + ((width - 1)//8 + 1) * 24
return _mvfont[doff + 2:next_offs], 24, width
-