gh-118761: Improve the import time of ``gettext`` (#128898)
``gettext`` is often imported in programs that may not end up translating anything. In fact, the ``struct`` module already has a delayed import when parsing ``GNUTranslations`` to speed up the no ``.mo`` files case. The re module is also used in the same situation, but behind a function chain only called by ``GNUTranslations``. Cache the compiled regex globally the first time it is used. The finditer function is converted to a method call on the compiled object which is slightly more efficient, and necessary for the delayed re import.
E
Eli Schwartz committed
c9c9fcb8fcc3ef43e1d8bd71ae0ed3d4231a6013
Parent: bbeb219
Committed by GitHub <noreply@github.com>
on 1/20/2025, 12:01:20 AM