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

Performance Improvement 1 - Reduce number of pure calls. #986

Merged
merged 1 commit into from
Nov 1, 2024
Merged
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
19 changes: 10 additions & 9 deletions djlint/formatter/indent.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,19 +88,22 @@ def fix_handlebars_template_tags(
ignored_level = 0

for item in rawcode_flat_list:
is_safe_closing_tag_ = is_safe_closing_tag(config, item)
is_ignored_block_opening_ = is_ignored_block_opening(config, item)

# if a raw tag first line
if not is_block_raw and is_ignored_block_opening(config, item):
if not is_block_raw and is_ignored_block_opening_:
is_raw_first_line = True

# if a raw tag then start ignoring
if is_ignored_block_opening(config, item):
if is_ignored_block_opening_:
is_block_raw = True
ignored_level += 1

if is_script_style_block_opening(config, item):
in_script_style_tag = True

if is_safe_closing_tag(config, item):
if is_safe_closing_tag_:
ignored_level -= 1
ignored_level = max(ignored_level, 0)
if is_block_raw and ignored_level == 0:
Expand Down Expand Up @@ -183,7 +186,7 @@ def fix_handlebars_template_tags(
flags=re.IGNORECASE | re.MULTILINE | re.VERBOSE,
)
and not is_block_raw
and not is_safe_closing_tag(config, item)
and not is_safe_closing_tag_
# and not ending in a slt like <span><strong></strong>.
and not re.findall(
rf"(<({slt_html})>)(.*?)(</(\2)>[^<]*?$)",
Expand Down Expand Up @@ -261,9 +264,7 @@ def fix_handlebars_template_tags(
tmp = (indent * indent_level) + item + "\n"
indent_level += 1

elif is_raw_first_line or (
is_safe_closing_tag(config, item) and not is_block_raw
):
elif is_raw_first_line or (is_safe_closing_tag_ and not is_block_raw):
tmp = (indent * indent_level) + item + "\n"

elif is_block_raw or not item.strip():
Expand All @@ -279,7 +280,7 @@ def fix_handlebars_template_tags(

# if a opening raw tag then start ignoring.. only if there is no closing tag
# on the same line
if is_ignored_block_opening(config, item):
if is_ignored_block_opening_:
is_block_raw = True
is_raw_first_line = False

Expand All @@ -302,7 +303,7 @@ def fix_handlebars_template_tags(
or is_script_style_block_closing(config, item)
):
in_script_style_tag = False
if not is_safe_closing_tag(config, item):
if not is_safe_closing_tag_:
ignored_level -= 1
ignored_level = max(ignored_level, 0)
if ignored_level == 0:
Expand Down