Skip to content
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

Make new_text_layout take impl Into<Arc<str>> #297

Merged
merged 1 commit into from
Sep 4, 2020
Merged

Conversation

cmyr
Copy link
Member

@cmyr cmyr commented Sep 4, 2020

This will still allow the simple case of passing a string slice, but
will also let druid share string objects with piet, which should enable
better APIs that aren't giving up efficiency.

Another benefit of this work is making cloning of layout objects
cheaper.

closes #295

@cmyr cmyr force-pushed the arc-str-in-layout branch from b444e77 to 02e8c59 Compare September 4, 2020 17:17
@cmyr
Copy link
Member Author

cmyr commented Sep 4, 2020

To explain the rationale here a bit better; besides just cheaper cloning, this fixes an issue that I ran into in linebender/druid#1182. Because we create the layout object lazily in druid, if we don't want to hold onto an additional copy of the text we need to have the text passed in whenever the layout object is rebuilt, which doesn't feel exactly right.

@cmyr cmyr force-pushed the arc-str-in-layout branch 2 times, most recently from 8650e46 to 4a8d7b6 Compare September 4, 2020 17:34
This will still allow the simple case of passing a string slice, but
will also let druid share string objects with piet, which should enable
better APIs that aren't giving up efficiency.

Another benefit of this work is making cloning of layout objects
cheaper.
@cmyr cmyr force-pushed the arc-str-in-layout branch from 4a8d7b6 to c79347f Compare September 4, 2020 17:36
Copy link
Contributor

@raphlinus raphlinus left a comment

Choose a reason for hiding this comment

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

Ok, this change is fine, but as discussed in chat this is bringing up some complex issues around cloning and mutability in the existing design - doing a mutation after a clone will affect the original copy. Some deeper thought is needed whether it's even worthwhile having a mutable width change, and if so how to keep it both safe and efficient. Colin will file an issue, and we can discuss there.

@cmyr
Copy link
Member Author

cmyr commented Sep 4, 2020

Okay, going to try this, I think it lets me write a much better API in druid.

@cmyr cmyr merged commit 4348b7d into master Sep 4, 2020
@cmyr cmyr deleted the arc-str-in-layout branch September 4, 2020 18:35
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.

TextLayout objects should store text as Arc<str> instead of String
2 participants