diff --git a/.changes/avoid-redundant-clone.md b/.changes/avoid-redundant-clone.md new file mode 100644 index 000000000..d57e72135 --- /dev/null +++ b/.changes/avoid-redundant-clone.md @@ -0,0 +1,5 @@ +--- +"wry": patch +--- + +Remove redundant `.clone()` calls and avoid unnecessary heap allocations. diff --git a/src/webview/android/mod.rs b/src/webview/android/mod.rs index 826bc8c6c..74011392b 100644 --- a/src/webview/android/mod.rs +++ b/src/webview/android/mod.rs @@ -143,11 +143,8 @@ impl InnerWebView { if let Some(u) = url { let mut url_string = String::from(u.as_str()); let name = u.scheme(); - let schemes = custom_protocols - .iter() - .map(|(name, _)| name.as_str()) - .collect::>(); - if schemes.contains(&name) { + let is_custom_protocol = custom_protocols.iter().any(|(n, _)| n == name); + if is_custom_protocol { url_string = u .as_str() .replace(&format!("{}://", name), &format!("https://{}.", name)) diff --git a/src/webview/mod.rs b/src/webview/mod.rs index 1c541aa80..7e7d0264d 100644 --- a/src/webview/mod.rs +++ b/src/webview/mod.rs @@ -853,15 +853,15 @@ pub trait WebviewExtMacOS { #[cfg(target_os = "macos")] impl WebviewExtMacOS for WebView { fn webview(&self) -> cocoa::base::id { - self.webview.webview.clone() + self.webview.webview } fn manager(&self) -> cocoa::base::id { - self.webview.manager.clone() + self.webview.manager } fn ns_window(&self) -> cocoa::base::id { - self.webview.ns_window.clone() + self.webview.ns_window } } diff --git a/src/webview/webview2/mod.rs b/src/webview/webview2/mod.rs index bd2eb34e6..d2ab5043f 100644 --- a/src/webview/webview2/mod.rs +++ b/src/webview/webview2/mod.rs @@ -794,7 +794,7 @@ window.addEventListener('mousemove', (e) => window.chrome.webview.postMessage('_ let uri = take_pwstr(pwstr); - Url::parse(&uri.to_string()).unwrap() + Url::parse(&uri).unwrap() } pub fn eval(&self, js: &str) -> Result<()> {