Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

⚡️ Speed up method Font._registered_font_key by 20% in core/src/toga/fonts.py #1

Open
wants to merge 1 commit into
base: codeflash-run
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions core/src/toga/fonts.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# Use the Travertino font definitions as-is
from travertino import constants
from travertino.constants import (
BOLD,
FONT_STYLES, FONT_VARIANTS, FONT_WEIGHTS, BOLD,
CURSIVE,
FANTASY,
ITALIC,
Expand Down Expand Up @@ -99,11 +99,9 @@ def _registered_font_key(
style: str,
variant: str,
) -> tuple[str, str, str, str]:
if weight not in constants.FONT_WEIGHTS:
weight = NORMAL
if style not in constants.FONT_STYLES:
style = NORMAL
if variant not in constants.FONT_VARIANTS:
variant = NORMAL

return family, weight, style, variant
return (
family,
weight if weight in FONT_WEIGHTS else NORMAL,
style if style in FONT_STYLES else NORMAL,
variant if variant in FONT_VARIANTS else NORMAL,
)
Loading