Skip to content

Commit

Permalink
_check_encoding: Improve efficiency by creating dict outside the for …
Browse files Browse the repository at this point in the history
…loop (#3648)
  • Loading branch information
seisman authored Nov 26, 2024
1 parent a29d513 commit 8ce81cc
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion pygmt/helpers/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,8 @@ def _check_encoding(argstr: str) -> Encoding:
charset["ZapfDingbats"].values()
)
for encoding in ["ISOLatin1+"] + [f"ISO-8859-{i}" for i in range(1, 17) if i != 12]:
if all(c in (set(charset[encoding].values()) | adobe_chars) for c in argstr):
chars = set(charset[encoding].values()) | adobe_chars
if all(c in chars for c in argstr):
return encoding # type: ignore[return-value]
# Return the "ISOLatin1+" encoding if the string contains characters from multiple
# charset encodings or contains characters that are not in any charset encoding.
Expand Down

0 comments on commit 8ce81cc

Please sign in to comment.