8000 Refactor `indent` Filter Implementation by strickczq · Pull Request #466 · askama-rs/askama · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Refactor indent Filter Implementation #466

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

Merged
merged 6 commits into from
May 29, 2025
Merged

Conversation

strickczq
Copy link
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.
@GuillaumeGomez
Copy link
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
Collaborator

Looks good to me, thanks!

Waiting for @Kijewski's review now. 😄

Copy link
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!

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
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
0