Skip to content

Commit

Permalink
Slightly speed up execution time of common cases (#142)
Browse files Browse the repository at this point in the history
  • Loading branch information
ofek committed Nov 15, 2021
1 parent c151139 commit 809a8ae
Showing 1 changed file with 10 additions and 8 deletions.
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

0 comments on commit 809a8ae

Please sign in to comment.