Skip to content

Refactor indent Filter Implementation#466

Merged
Kijewski merged 6 commits intoaskama-rs:masterfrom
strickczq:master
May 29, 2025
Merged

Refactor indent Filter Implementation#466
Kijewski merged 6 commits intoaskama-rs:masterfrom
strickczq:master

Conversation

@strickczq
Copy link
Copy Markdown
Contributor

Description

This PR refactors the indent filter:

  1. Rewrote indent filter to use IndentWriter, eliminating memory allocation, removing MAX_LEN restriction, and dropping the fuzzed_indent_filter test.
  2. Moved indent filter from alloc.rs to a new indent.rs file, as it no longer requires memory allocation, and updated module imports/exports.

Special thanks to @Kijewski for their suggestion in issue #465 to rewrite the filter without intermediate allocations, which inspired this optimization.

Changes

  • Rewrote indent filter to use IndentWriter, removing memory allocation and MAX_LEN.
  • Moved indent filter to indent.rs, removed unused dependencies (Cow, Deref, Pin) from alloc.rs, and updated filters/mod.rs.

Testing

  • Existing tests for indent filter pass.
  • Removed fuzzed_indent_filter test as it's no longer relevant.

Related Issues

strickczq added 2 commits May 29, 2025 21:51
Refactored the `indent` filter implementation to introduce the `IndentWriter` struct,
eliminating the need for memory allocation.

Removed the `MAX_LEN` restriction and the `fuzzed_indent_filter` test,
as they are no longer necessary with the new approach.

Fixes askama-rs#465.
Relocated the `indent` filter implementation from alloc.rs to a new indent.rs file,
as it no longer requires memory allocation.

Updated module imports and exports in filters/mod.rs to reflect this change.

Removed unused dependencies
    (Cow, Deref, Pin) from alloc.rs.
Comment thread askama/src/filters/indent.rs Outdated
Comment thread askama/src/filters/indent.rs Outdated
Comment thread askama/src/filters/indent.rs Outdated
@GuillaumeGomez
Copy link
Copy Markdown
Collaborator

Solid start. Almost nothing to be changed, well done!

In addition to my comments, please also update the book "filters" chapter to remove the mention of the alloc feature on indent filter.

strickczq added 2 commits May 29, 2025 22:35
Updated the "filters" chapter in the book to remove the mention of the alloc feature requirement for the indent filter, as it no longer relies on memory allocation.
GuillaumeGomez
GuillaumeGomez previously approved these changes May 29, 2025
@GuillaumeGomez
Copy link
Copy Markdown
Collaborator

Looks good to me, thanks!

Waiting for @Kijewski's review now. 😄

Copy link
Copy Markdown
Member

@Kijewski Kijewski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I only found this one logic problem, otherwise the PR looks great, thank you!

Comment thread askama/src/filters/indent.rs Outdated
Fix logic issue where `self.first` was not tracked across calls, causing incorrect indentation.

Replaced `idx` with `is_first_line` flag.

Added `test_indent_chunked` to verify correct behavior.
Copy link
Copy Markdown
Member

@Kijewski Kijewski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you very much for fixing the problem! Good idea to add a test that splits up the input!

@Kijewski Kijewski merged commit c40e828 into askama-rs:master May 29, 2025
39 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

indent filter fails to apply indentation for large input strings

3 participants