From 5d9677038b11b33a86d9cda90659e39a1a69a450 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 28 Jul 2022 12:20:27 -0600 Subject: [PATCH] [varLib.iup] Compile with Cython when available Even with no annotations, makes it ~35% faster. --- Lib/fontTools/varLib/iup.py | 14 ++++++++++++++ setup.py | 3 +++ 2 files changed, 17 insertions(+) diff --git a/Lib/fontTools/varLib/iup.py b/Lib/fontTools/varLib/iup.py index 0bd797a24..02ae27ef0 100644 --- a/Lib/fontTools/varLib/iup.py +++ b/Lib/fontTools/varLib/iup.py @@ -1,3 +1,17 @@ +try: + import cython +except ImportError: + # if cython not installed, use mock module with no-op decorators and types + from fontTools.misc import cython + +if cython.compiled: + # Yep, I'm compiled. + COMPILED = True +else: + # Just a lowly interpreted script. + COMPILED = False + + MAX_LOOKBACK = 8 def iup_segment(coords, rc1, rd1, rc2, rd2): diff --git a/setup.py b/setup.py index b252d93ce..f5760c06a 100755 --- a/setup.py +++ b/setup.py @@ -68,6 +68,9 @@ if with_cython is True or (with_cython is None and has_cython): ext_modules.append( Extension("fontTools.cu2qu.cu2qu", ["Lib/fontTools/cu2qu/cu2qu.py"]), ) + ext_modules.append( + Extension("fontTools.varLib.iup", ["Lib/fontTools/varLib/iup.py"]), + ) extras_require = { # for fontTools.ufoLib: to read/write UFO fonts