-
Notifications
You must be signed in to change notification settings - Fork 27
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
Conversation
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.
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 |
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.
Looks good to me, thanks! Waiting for @Kijewski's review now. 😄 |
There was a problem hiding this 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.
There was a problem hiding this 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!
Description
This PR refactors the
indent
filter:indent
filter to useIndentWriter
, eliminating memory allocation, removingMAX_LEN
restriction, and dropping thefuzzed_indent_filter
test.indent
filter fromalloc.rs
to a newindent.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
indent
filter to useIndentWriter
, removing memory allocation andMAX_LEN
.indent
filter toindent.rs
, removed unused dependencies (Cow
,Deref
,Pin
) fromalloc.rs
, and updatedfilters/mod.rs
.Testing
indent
filter pass.fuzzed_indent_filter
test as it's no longer relevant.Related Issues
indent
filter fails to apply indentation for large input strings #465