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

Slightly speed up execution time of common cases #142

Merged
merged 6 commits into from Nov 15, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 10 additions & 8 deletions tomli/_parser.py
Expand Up @@ -584,6 +584,8 @@ def parse_value( # noqa: C901
except IndexError:
char = None

# IMPORTANT: order conditions based on speed of checking and likelihood

# Basic strings
if char == '"':
if src.startswith('"""', pos):
Expand All @@ -604,6 +606,14 @@ def parse_value( # noqa: C901
if src.startswith("false", pos):
return pos + 5, False

# Arrays
if char == "[":
return parse_array(src, pos, parse_float)

# Inline tables
if char == "{":
return parse_inline_table(src, pos, parse_float)

# Dates and times
datetime_match = RE_DATETIME.match(src, pos)
if datetime_match:
Expand All @@ -623,14 +633,6 @@ def parse_value( # noqa: C901
if number_match:
return number_match.end(), match_to_number(number_match, parse_float)

# Arrays
if char == "[":
return parse_array(src, pos, parse_float)

# Inline tables
if char == "{":
return parse_inline_table(src, pos, parse_float)

# Special floats
first_three = src[pos : pos + 3]
if first_three in {"inf", "nan"}:
Expand Down