Skip to content

Commit 95fc3cd

Browse files
chore: cleanup a few unneeded clones (#12733)
1 parent 4633705 commit 95fc3cd

File tree

6 files changed

+27
-52
lines changed

6 files changed

+27
-52
lines changed

crates/tauri/src/ipc/protocol.rs

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ pub fn get<R: Runtime>(manager: Arc<AppManager<R>>) -> UriSchemeProtocolHandler
4545
)
4646
.entered();
4747

48-
let manager = manager.clone();
49-
5048
let respond = move |mut response: http::Response<Cow<'static, [u8]>>| {
5149
response
5250
.headers_mut()
@@ -113,7 +111,7 @@ pub fn get<R: Runtime>(manager: Arc<AppManager<R>>) -> UriSchemeProtocolHandler
113111

114112
let (mut response, mime_type) = match response {
115113
InvokeResponse::Ok(InvokeResponseBody::Json(v)) => (
116-
http::Response::new(v.as_bytes().to_vec().into()),
114+
http::Response::new(v.into_bytes().into()),
117115
mime::APPLICATION_JSON,
118116
),
119117
InvokeResponse::Ok(InvokeResponseBody::Raw(v)) => (
@@ -147,7 +145,7 @@ pub fn get<R: Runtime>(manager: Arc<AppManager<R>>) -> UriSchemeProtocolHandler
147145
http::Response::builder()
148146
.status(StatusCode::INTERNAL_SERVER_ERROR)
149147
.header(CONTENT_TYPE, mime::TEXT_PLAIN.essence_str())
150-
.body(e.as_bytes().to_vec().into())
148+
.body(e.into_bytes().into())
151149
.unwrap(),
152150
);
153151
}
@@ -157,12 +155,7 @@ pub fn get<R: Runtime>(manager: Arc<AppManager<R>>) -> UriSchemeProtocolHandler
157155
http::Response::builder()
158156
.status(StatusCode::INTERNAL_SERVER_ERROR)
159157
.header(CONTENT_TYPE, mime::TEXT_PLAIN.essence_str())
160-
.body(
161-
"failed to acquire webview reference"
162-
.as_bytes()
163-
.to_vec()
164-
.into(),
165-
)
158+
.body("failed to acquire webview reference".as_bytes().into())
166159
.unwrap(),
167160
);
168161
}
@@ -177,12 +170,7 @@ pub fn get<R: Runtime>(manager: Arc<AppManager<R>>) -> UriSchemeProtocolHandler
177170
}
178171

179172
_ => {
180-
let mut r = http::Response::new(
181-
"only POST and OPTIONS are allowed"
182-
.as_bytes()
183-
.to_vec()
184-
.into(),
185-
);
173+
let mut r = http::Response::new("only POST and OPTIONS are allowed".as_bytes().into());
186174
*r.status_mut() = StatusCode::METHOD_NOT_ALLOWED;
187175
r.headers_mut().insert(
188176
CONTENT_TYPE,
@@ -414,8 +402,8 @@ fn handle_ipc_message<R: Runtime>(request: Request<String>, manager: &AppManager
414402
error,
415403
);
416404
} else {
417-
let _ = Channel::from_callback_fn(webview, callback)
418-
.send(InvokeResponseBody::Raw(v.clone()));
405+
let _ =
406+
Channel::from_callback_fn(webview, callback).send(InvokeResponseBody::Raw(v));
419407
}
420408
}
421409
InvokeResponse::Err(e) => responder_eval(

crates/tauri/src/manager/mod.rs

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -404,27 +404,23 @@ impl<R: Runtime> AppManager<R> {
404404
let mut asset_path = AssetKey::from(path.as_str());
405405

406406
let asset_response = assets
407-
.get(&path.as_str().into())
407+
.get(&asset_path)
408408
.or_else(|| {
409409
log::debug!("Asset `{path}` not found; fallback to {path}.html");
410-
let fallback = format!("{}.html", path.as_str()).into();
410+
let fallback = format!("{path}.html").into();
411411
let asset = assets.get(&fallback);
412412
asset_path = fallback;
413413
asset
414414
})
415415
.or_else(|| {
416-
log::debug!(
417-
"Asset `{}` not found; fallback to {}/index.html",
418-
path,
419-
path
420-
);
421-
let fallback = format!("{}/index.html", path.as_str()).into();
416+
log::debug!("Asset `{path}` not found; fallback to {path}/index.html",);
417+
let fallback = format!("{path}/index.html").into();
422418
let asset = assets.get(&fallback);
423419
asset_path = fallback;
424420
asset
425421
})
426422
.or_else(|| {
427-
log::debug!("Asset `{}` not found; fallback to index.html", path);
423+
log::debug!("Asset `{path}` not found; fallback to index.html");
428424
let fallback = AssetKey::from("index.html");
429425
let asset = assets.get(&fallback);
430426
asset_path = fallback;
@@ -457,13 +453,13 @@ impl<R: Runtime> AppManager<R> {
457453
csp_header.replace(Csp::DirectiveMap(csp_map).to_string());
458454
}
459455

460-
asset.as_bytes().to_vec()
456+
asset.into_bytes()
461457
} else {
462458
asset
463459
};
464460
let mime_type = tauri_utils::mime_type::MimeType::parse(&final_data, &path);
465461
Ok(Asset {
466-
bytes: final_data.to_vec(),
462+
bytes: final_data,
467463
mime_type,
468464
csp_header,
469465
})
@@ -555,14 +551,8 @@ impl<R: Runtime> AppManager<R> {
555551
};
556552

557553
let listeners = self.listeners();
558-
let webviews = self
559-
.webview
560-
.webviews_lock()
561-
.values()
562-
.cloned()
563-
.collect::<Vec<_>>();
564-
565-
listeners.emit_js(webviews.iter(), &emit_args)?;
554+
555+
listeners.emit_js(self.webview.webviews_lock().values(), &emit_args)?;
566556
listeners.emit(emit_args)?;
567557

568558
Ok(())

crates/tauri/src/manager/webview.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -226,16 +226,13 @@ impl<R: Runtime> WebviewManager<R> {
226226
let protocol = protocol.clone();
227227
let app_handle = manager.app_handle().clone();
228228

229-
pending.register_uri_scheme_protocol(
230-
uri_scheme.clone(),
231-
move |webview_id, request, responder| {
232-
let context = UriSchemeContext {
233-
app_handle: &app_handle,
234-
webview_label: webview_id,
235-
};
236-
(protocol.protocol)(context, request, UriSchemeResponder(responder))
237-
},
238-
);
229+
pending.register_uri_scheme_protocol(uri_scheme, move |webview_id, request, responder| {
230+
let context = UriSchemeContext {
231+
app_handle: &app_handle,
232+
webview_label: webview_id,
233+
};
234+
(protocol.protocol)(context, request, UriSchemeResponder(responder))
235+
});
239236
}
240237

241238
let window_url = Url::parse(&pending.url).unwrap();
@@ -314,7 +311,7 @@ impl<R: Runtime> WebviewManager<R> {
314311
.get::<crate::Scopes>()
315312
.asset_protocol
316313
.clone();
317-
let protocol = crate::protocol::asset::get(asset_scope.clone(), window_origin.clone());
314+
let protocol = crate::protocol::asset::get(asset_scope, window_origin.clone());
318315
pending.register_uri_scheme_protocol("asset", move |webview_id, request, responder| {
319316
protocol(webview_id, request, UriSchemeResponder(responder))
320317
});

crates/tauri/src/protocol/asset.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub fn get(scope: scope::fs::Scope, window_origin: String) -> UriSchemeProtocolH
1919
.status(http::StatusCode::INTERNAL_SERVER_ERROR)
2020
.header(CONTENT_TYPE, mime::TEXT_PLAIN.essence_str())
2121
.header("Access-Control-Allow-Origin", &window_origin)
22-
.body(e.to_string().as_bytes().to_vec())
22+
.body(e.to_string().into_bytes())
2323
.unwrap(),
2424
),
2525
},

crates/tauri/src/protocol/isolation.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ pub fn get<R: Runtime>(
5959
.add_configured_headers(manager.config.app.security.headers.as_ref())
6060
.header(CONTENT_TYPE, mime::TEXT_HTML.as_ref())
6161
.header("Content-Security-Policy", csp)
62-
.body(asset.into_string().as_bytes().to_vec()),
62+
.body(asset.into_string().into_bytes()),
6363
Err(_) => http::Response::builder()
6464
.status(http::StatusCode::INTERNAL_SERVER_ERROR)
6565
.header(CONTENT_TYPE, mime::TEXT_PLAIN.as_ref())
@@ -84,7 +84,7 @@ pub fn get<R: Runtime>(
8484
responder.respond(
8585
http::Response::builder()
8686
.status(http::StatusCode::INTERNAL_SERVER_ERROR)
87-
.body("failed to get response".as_bytes().to_vec())
87+
.body("failed to get response".as_bytes())
8888
.unwrap(),
8989
);
9090
}

crates/tauri/src/protocol/tauri.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ pub fn get<R: Runtime>(
6161
.status(StatusCode::INTERNAL_SERVER_ERROR)
6262
.header(CONTENT_TYPE, mime::TEXT_PLAIN.essence_str())
6363
.header("Access-Control-Allow-Origin", &window_origin)
64-
.body(e.to_string().as_bytes().to_vec())
64+
.body(e.to_string().into_bytes())
6565
.unwrap(),
6666
),
6767
}

0 commit comments

Comments
 (0)