-
Notifications
You must be signed in to change notification settings - Fork 4
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
is using clone on ToString function really important? #32
Comments
It's a good note. You can work on it if you would like that :) See CONTRIBUTING.md. |
Sure I have 2 ways in my mind first is using reference to string instead of cloning and using COW(copy on write) which gives you optional ownership where it lazily copy the string which helps us encountering unnecessary cloning, your thoughts on it? |
Also can you check the pull req and guide me on it |
tried using COW but the conversion of Scripts and styles from pathbufs to strings vice versa is difficult to handle with it ,I am trying to find a way to do that |
// crates/metassr-build/src/server/renderer/page.rs
pub fn render(&self) -> Result<String> {
Ok(HtmlRenderer::new(&self.head, &self.body, &self.entries)
.render()?
.to_string())
} I think it's useless to implement impl HtmlOutput {
pub fn into_inner(self) -> String {
self.0
}
} Isn't that better? What do you think? |
Yaa this could be a better solution than cloning everytime |
@Gulshan1-3 Would you like to refactor it? |
sure i have to use the above approch you suggested? |
Yup, otherwise if you have something better |
In https://github.com/metacall/metassr/blob/master/crates/html-generator/src/builder.rs#L27 we made a ToString method for HtmlOutput and we are cloning the string which is expensive is it important to clone the string cant we just use less expensive methods.
impl ToString for HtmlOutput { fn to_string(&self) -> String { self.0.clone() } }
The text was updated successfully, but these errors were encountered: