Skip to content

Commit 433a0f2

Browse files
authored
Avoid string copy for Key: From<String> implementation (#3858)
The macro uses `to_string().as_str()` which copies the string. Avoid that by using `as_str()` directly on the source. Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
1 parent a86c4f8 commit 433a0f2

File tree

1 file changed

+6
-1
lines changed
  • packages/yew/src/virtual_dom

1 file changed

+6
-1
lines changed

packages/yew/src/virtual_dom/key.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ impl From<&'_ str> for Key {
4141
}
4242
}
4343

44+
impl From<String> for Key {
45+
fn from(key: String) -> Self {
46+
Self::from(key.as_str())
47+
}
48+
}
49+
4450
impl ImplicitClone for Key {}
4551

4652
macro_rules! key_impl_from_to_string {
@@ -53,7 +59,6 @@ macro_rules! key_impl_from_to_string {
5359
};
5460
}
5561

56-
key_impl_from_to_string!(String);
5762
key_impl_from_to_string!(char);
5863
key_impl_from_to_string!(u8);
5964
key_impl_from_to_string!(u16);

0 commit comments

Comments
 (0)