-
Notifications
You must be signed in to change notification settings - Fork 86
Allocate a lot less #202
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
Open
tanculau
wants to merge
28
commits into
colored-rs:master
Choose a base branch
from
tanculau:less-alloc
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Allocate a lot less #202
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
7b06a7b
Replace compute_stlye with a Writer
tanculau 1ad8d71
fmt
tanculau 82fa2c2
Replace loop with insert_str
tanculau 19faeba
Replaced escape_inner_reset_sequences
tanculau 19eec9b
Fix tests
tanculau 0c6f6c3
Cleanup
tanculau d540f3d
Change Helper Structs to Tuples
tanculau b217771
Padding without alloc
tanculau 0ae0b78
Enhance formatting tests
tanculau 57c53ea
Enhance formatting tests
tanculau ecd6355
Cleanup
tanculau 098fa4f
Remove duplicate code
tanculau 34eaf1a
Remove alloc in closest_color_euclidean
tanculau baf9453
Replace min_by with min_by_key
tanculau 1e04c4d
Add comments
tanculau 962a9ed
Refactor distance calculation in color comparison
tanculau d5cd420
Add tests to check if fmt and to_str are equal
tanculau 3e7932b
Split up formatting test and added some
tanculau d2d4d93
Cleanup
tanculau 383397e
Move tests to their modul
tanculau 362f667
Typo
tanculau 2cd3492
Enhance formatting, escape and color_fn tests
tanculau 432ebe7
Remove allocations in Style
tanculau aae4077
Merge branch 'master' into less-alloc
tanculau 2497bd0
Add doc comments & AnsiColor test
tanculau a122bea
Reworked to_static_str, Removed Helper structs, moved formatting in i…
tanculau 5270a3c
Merge branch 'master' into less-alloc
tanculau a561d42
cargo fmt
tanculau File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 think this test touches on something interesting. the
to_*_fmt
andto_*_str
copy a lot of the same logic.You've defined wrappers the implement
Display
here, but, TBH, I think this is a sign to de-duplicate the logic between the format and string methods. The string methods should call the format methods.But that's probably for a separate PR. The reason I bring it up is that, if I'm reading this correctly, what this tests is "did we copy and paste the logic between the two functions?" I'm not a fan of that type of test. Rather a test like this:
I'd rather have tests like this:
That might look redundant, but redundancy is OK in tests IMO.
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 reworked the code, so that there should be as little code duplication as possible.
The problem is, that this is a public interface. As such I cannot change it.
The requirement is, that formatting and the to_str method should always have the same output.
But we cannot write a static str, such that we cannot just call formatting from to_str.
We also want to support precision and advanced formatting. So we also cannot call to_str from the formatting code.
So, if I see it correctly, we have duplicate public interfaces. To check, that both interfaces behave the same, we just call them against each other. So in the end, I only need to test one of them to make sure both work.
The test is also there to protect in the future, if a change occurs, that this requirement is not forgotten.
Another option would be to just write a doc comment and hope that everyone reads it.
I think the solution right now should be okay.