Open
Conversation
1954f8a to
c556be3
Compare
c556be3 to
208a45e
Compare
Member
|
This now has conflicts after merging #97 |
31da20e to
829258a
Compare
Contributor
Author
|
The conflicts are resolved, but the CI fails right now, caused by duplicate |
Contributor
|
FWIW point 1 can probably be addressed via using |
Contributor
There was a problem hiding this comment.
I think the changes here seem reasonable as it will help simplify the overall usage of Attr's.
My only Concern is how will this affect the overall performance since we are moving towards clones more than copy. @jackpot51 what do you think?
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Currently, there exist the borrowing
Attrsand the owningAttrsOwned, which only differ in their usage ofFamilyvsFamilyOwned. In theory, this allows passingAttrswithout having to allocate. In practice, we have the following situation:FontSystem::get_font_matcheswants to prevent an allocation in the most-common case that a cached match already exists, but it can't (seecosmic-text/src/font/system/std.rs
Line 130 in 1bc198f
Borrow<Attrs>forAttrsOwned.AttrsOwnedinAttrsList, so it is almost impossible to not have anAttrsturn into anAttrsOwnedsomewhere down the line.This PR removes the old
Attrs, renamesAttrsOwnedtoAttrsand adds anAttrsBuilder, which has the same helper methods as the oldAttrs. This PR also includes several changes to prevent allocations in many cases:FamilyOwneduses aCow<'static, str>instead ofString, allowing the use of string literals without allocating.AttrsBuilder::familytakes animpl Into<FamilyOwned>, which is only implemented forFamilyOwnedorFamily<'static>, so users need to explicity useFamilyOwned::newif they want to use a non staticFamily.AttrsimplementsAsRef<Attrs>andFrom<&Attrs>, allowing methods that might need to store theAttrsto accept both values and references ofAttrs, while at the same time preventing an extra allocation when a value is passed.Attrsnow not beingCopy, users have to explicitly useclone, which makes potential allocations more obvious.This PR also changes
FontSystem::get_font_matchesto take animpl AsRef<Attrs> + Into<Attrs>parameter, which it only clones if (a) the passed argument is a reference and (b) the cache does not contain an equivalentAttrs. So this change leads to probably less allocations overall.