From 81b9fc9d92bb74aa8428ae4db39bd84e8c16095c Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sat, 20 Jun 2026 18:34:54 +0900 Subject: refactor(php-shim): drop Box wrapping from PhpMixed List/Array The List and Array variants of PhpMixed boxed their elements unnecessarily. Store PhpMixed values directly and update all callers accordingly. Co-Authored-By: Claude Opus 4.8 (1M context) --- crates/shirabe/src/util/auth_helper.rs | 37 ++--- crates/shirabe/src/util/bitbucket.rs | 42 ++--- crates/shirabe/src/util/config_validator.rs | 18 +- crates/shirabe/src/util/filesystem.rs | 12 +- crates/shirabe/src/util/forgejo.rs | 9 +- crates/shirabe/src/util/git.rs | 19 +-- crates/shirabe/src/util/gitlab.rs | 69 +++----- crates/shirabe/src/util/http/curl_downloader.rs | 193 +++++++--------------- crates/shirabe/src/util/http_downloader.rs | 19 +-- crates/shirabe/src/util/no_proxy_pattern.rs | 2 +- crates/shirabe/src/util/perforce.rs | 57 ++----- crates/shirabe/src/util/platform.rs | 4 +- crates/shirabe/src/util/process_executor.rs | 34 ++-- crates/shirabe/src/util/remote_filesystem.rs | 26 +-- crates/shirabe/src/util/stream_context_factory.rs | 62 +++---- crates/shirabe/src/util/svn.rs | 6 +- 16 files changed, 206 insertions(+), 403 deletions(-) (limited to 'crates/shirabe/src/util') diff --git a/crates/shirabe/src/util/auth_helper.rs b/crates/shirabe/src/util/auth_helper.rs index 5952429..d8b77ac 100644 --- a/crates/shirabe/src/util/auth_helper.rs +++ b/crates/shirabe/src/util/auth_helper.rs @@ -77,8 +77,8 @@ impl AuthHelper { if in_array( PhpMixed::String(input.clone()), &PhpMixed::List(vec![ - Box::new(PhpMixed::String("y".to_string())), - Box::new(PhpMixed::String("n".to_string())), + PhpMixed::String("y".to_string()), + PhpMixed::String("n".to_string()), ]), false, ) { @@ -106,7 +106,7 @@ impl AuthHelper { .borrow() .get_authentication(origin) .into_iter() - .map(|(k, v)| (k, Box::new(v.map_or(PhpMixed::Null, PhpMixed::String)))) + .map(|(k, v)| (k, v.map_or(PhpMixed::Null, PhpMixed::String))) .collect(), ), )?; @@ -256,9 +256,9 @@ impl AuthHelper { if in_array( PhpMixed::String(password), &PhpMixed::List(vec![ - Box::new(PhpMixed::String("gitlab-ci-token".to_string())), - Box::new(PhpMixed::String("private-token".to_string())), - Box::new(PhpMixed::String("oauth2".to_string())), + PhpMixed::String("gitlab-ci-token".to_string()), + PhpMixed::String("private-token".to_string()), + PhpMixed::String("oauth2".to_string()), ]), true, ) { @@ -463,7 +463,7 @@ impl AuthHelper { false }; if !http_has_header && let Some(PhpMixed::Array(http)) = options.get_mut("http") { - http.insert("header".to_string(), Box::new(PhpMixed::List(vec![]))); + http.insert("header".to_string(), PhpMixed::List(vec![])); } } @@ -475,7 +475,7 @@ impl AuthHelper { .and_then(|h| h.get("header")) .and_then(|v| v.as_list()) { - Some(list) => list.iter().map(|b| (**b).clone()).collect(), + Some(list) => list.iter().cloned().collect(), None => vec![], }; @@ -504,11 +504,11 @@ impl AuthHelper { if is_array(&custom_headers) { if let Some(arr) = custom_headers.as_array() { for header in arr.values() { - headers.push((**header).clone()); + headers.push(header.clone()); } } else if let Some(list) = custom_headers.as_list() { for header in list { - headers.push((**header).clone()); + headers.push(header.clone()); } } authentication_display_message = @@ -527,9 +527,9 @@ impl AuthHelper { } else if in_array( PhpMixed::String(password.clone()), &PhpMixed::List(vec![ - Box::new(PhpMixed::String("oauth2".to_string())), - Box::new(PhpMixed::String("private-token".to_string())), - Box::new(PhpMixed::String("gitlab-ci-token".to_string())), + PhpMixed::String("oauth2".to_string()), + PhpMixed::String("private-token".to_string()), + PhpMixed::String("gitlab-ci-token".to_string()), ]), true, ) && in_array( @@ -539,7 +539,7 @@ impl AuthHelper { .borrow_mut() .get("gitlab-domains") .as_array() - .map(|a| a.values().cloned().collect()) + .map(|a| a.values().map(|v| v.clone()).collect()) .unwrap_or_default(), ), true, @@ -605,8 +605,8 @@ impl AuthHelper { } else if in_array( PhpMixed::String(origin.to_string()), &PhpMixed::List(vec![ - Box::new(PhpMixed::String("api.bitbucket.org".to_string())), - Box::new(PhpMixed::String("api.github.com".to_string())), + PhpMixed::String("api.bitbucket.org".to_string()), + PhpMixed::String("api.github.com".to_string()), ]), true, ) { @@ -615,10 +615,7 @@ impl AuthHelper { // write headers back into options['http']['header'] if let Some(PhpMixed::Array(http)) = options.get_mut("http") { - http.insert( - "header".to_string(), - Box::new(PhpMixed::List(headers.into_iter().map(Box::new).collect())), - ); + http.insert("header".to_string(), PhpMixed::List(headers)); } Ok(options) diff --git a/crates/shirabe/src/util/bitbucket.rs b/crates/shirabe/src/util/bitbucket.rs index 0584308..26a9e65 100644 --- a/crates/shirabe/src/util/bitbucket.rs +++ b/crates/shirabe/src/util/bitbucket.rs @@ -102,24 +102,14 @@ impl Bitbucket { fn request_access_token(&mut self) -> anyhow::Result { let mut http = IndexMap::new(); - http.insert( - "method".to_string(), - Box::new(PhpMixed::String("POST".to_string())), - ); + http.insert("method".to_string(), PhpMixed::String("POST".to_string())); http.insert( "content".to_string(), - Box::new(PhpMixed::String( - "grant_type=client_credentials".to_string(), - )), - ); - let mut options = IndexMap::new(); - options.insert( - "retry-auth-failure".to_string(), - Box::new(PhpMixed::Bool(false)), + PhpMixed::String("grant_type=client_credentials".to_string()), ); - options.insert("http".to_string(), Box::new(PhpMixed::Array(http))); - let options: IndexMap = - options.into_iter().map(|(k, v)| (k, *v)).collect(); + let mut options: IndexMap = IndexMap::new(); + options.insert("retry-auth-failure".to_string(), PhpMixed::Bool(false)); + options.insert("http".to_string(), PhpMixed::Array(http)); let response = match self .http_downloader @@ -198,7 +188,7 @@ impl Bitbucket { } .into()); } - self.token = Some(token_map.into_iter().map(|(k, v)| (k, *v)).collect()); + self.token = Some(token_map.into_iter().collect()); Ok(true) } @@ -389,12 +379,8 @@ impl Bitbucket { .get("expires_in") .and_then(|v| v.as_int()) .ok_or_else(|| { - let token_mixed = PhpMixed::Array( - token - .iter() - .map(|(k, v)| (k.clone(), Box::new(v.clone()))) - .collect(), - ); + let token_mixed = + PhpMixed::Array(token.iter().map(|(k, v)| (k.clone(), v.clone())).collect()); LogicException { message: format!( "Expected a token configured with expires_in present, got {}", @@ -405,22 +391,22 @@ impl Bitbucket { })?; let t = self.time.unwrap_or_else(time); - let mut consumer: IndexMap> = IndexMap::new(); + let mut consumer = IndexMap::new(); consumer.insert( "consumer-key".to_string(), - Box::new(PhpMixed::String(consumer_key.to_string())), + PhpMixed::String(consumer_key.to_string()), ); consumer.insert( "consumer-secret".to_string(), - Box::new(PhpMixed::String(consumer_secret.to_string())), + PhpMixed::String(consumer_secret.to_string()), ); consumer.insert( "access-token".to_string(), - Box::new(token.get("access_token").cloned().unwrap_or(PhpMixed::Null)), + token.get("access_token").cloned().unwrap_or(PhpMixed::Null), ); consumer.insert( "access-token-expiration".to_string(), - Box::new(PhpMixed::Int(t + expires_in)), + PhpMixed::Int(t + expires_in), ); self.config @@ -465,7 +451,7 @@ impl Bitbucket { return false; } - let access_token = match origin_config.get("access-token").map(|v| *v.clone()) { + let access_token = match origin_config.get("access-token").map(|v| v.clone()) { Some(t) => t, None => return false, }; diff --git a/crates/shirabe/src/util/config_validator.rs b/crates/shirabe/src/util/config_validator.rs index a3f6ef7..033e6b3 100644 --- a/crates/shirabe/src/util/config_validator.rs +++ b/crates/shirabe/src/util/config_validator.rs @@ -43,7 +43,7 @@ impl ConfigValidator { .expect("config file path is always local"); let schema_result: anyhow::Result<()> = (|| -> anyhow::Result<()> { manifest = Some(match json.read()? { - PhpMixed::Array(m) => m.into_iter().map(|(k, v)| (k, *v)).collect(), + PhpMixed::Array(m) => m, _ => IndexMap::new(), }); json.validate_schema(JsonFile::LAX_SCHEMA, None)?; @@ -108,7 +108,7 @@ impl ConfigValidator { PhpMixed::List(list) => list .iter() .filter_map(|v| { - if let PhpMixed::String(s) = v.as_ref() { + if let PhpMixed::String(s) = v { Some(s.clone()) } else { None @@ -235,10 +235,10 @@ impl ConfigValidator { Some(PhpMixed::Array(m)) => m.clone(), _ => IndexMap::new(), }; - let mut packages: IndexMap> = require; + let mut packages: IndexMap = require; packages.extend(require_dev); for (package, version) in &packages { - if let PhpMixed::String(version_str) = version.as_ref() + if let PhpMixed::String(version_str) = version && Preg::is_match(r"{#}", version_str) { warnings.push(format!( @@ -282,12 +282,12 @@ impl ConfigValidator { // check for empty psr-0/psr-4 namespace prefixes if let Some(PhpMixed::Array(autoload)) = manifest.get("autoload") { - if let Some(PhpMixed::Array(psr0)) = autoload.get("psr-0").map(|v| v.as_ref()) + if let Some(PhpMixed::Array(psr0)) = autoload.get("psr-0") && psr0.contains_key("") { warnings.push("Defining autoload.psr-0 with an empty namespace prefix is a bad idea for performance".to_string()); } - if let Some(PhpMixed::Array(psr4)) = autoload.get("psr-4").map(|v| v.as_ref()) + if let Some(PhpMixed::Array(psr4)) = autoload.get("psr-4") && psr4.contains_key("") { warnings.push("Defining autoload.psr-4 with an empty namespace prefix is a bad idea for performance".to_string()); @@ -310,11 +310,7 @@ impl ConfigValidator { PhpMixed::String("dummy/dummy".to_string()), ); } - let manifest_boxed: IndexMap> = manifest_for_load - .into_iter() - .map(|(k, v)| (k, Box::new(v))) - .collect(); - match loader.load(manifest_boxed, "Composer\\Package\\CompletePackage") { + match loader.load(manifest_for_load, "Composer\\Package\\CompletePackage") { Ok(_) => {} Err(e) => { if let Some(invalid_e) = e.downcast_ref::() { diff --git a/crates/shirabe/src/util/filesystem.rs b/crates/shirabe/src/util/filesystem.rs index 50112ea..6ca6be0 100644 --- a/crates/shirabe/src/util/filesystem.rs +++ b/crates/shirabe/src/util/filesystem.rs @@ -107,11 +107,7 @@ impl Filesystem { let result = self .get_process() .execute( - PhpMixed::List( - cmd.iter() - .map(|s| Box::new(PhpMixed::String(s.clone()))) - .collect(), - ), + PhpMixed::List(cmd.iter().map(|s| PhpMixed::String(s.clone())).collect()), Some(&mut output), (), ) @@ -152,11 +148,7 @@ impl Filesystem { let process = self .get_process() .execute_async( - PhpMixed::List( - cmd.iter() - .map(|s| Box::new(PhpMixed::String(s.clone()))) - .collect(), - ), + PhpMixed::List(cmd.iter().map(|s| PhpMixed::String(s.clone())).collect()), (), ) .await?; diff --git a/crates/shirabe/src/util/forgejo.rs b/crates/shirabe/src/util/forgejo.rs index 974fb4a..4ca4710 100644 --- a/crates/shirabe/src/util/forgejo.rs +++ b/crates/shirabe/src/util/forgejo.rs @@ -149,11 +149,10 @@ impl Forgejo { cfg.get_config_source_mut() .remove_config_setting(&setting_key)?; } - let value: shirabe_php_shim::PhpMixed = - shirabe_php_shim::PhpMixed::Array(indexmap::indexmap! { - "username".to_string() => Box::new(username.clone().into()), - "token".to_string() => Box::new(token.clone().into()), - }); + let value = shirabe_php_shim::PhpMixed::Array(indexmap::indexmap! { + "username".to_string() => username.clone().into(), + "token".to_string() => token.clone().into(), + }); if store_in_local_auth_config && has_local_auth { let mut cfg = self.config.borrow_mut(); if let Some(local) = cfg.get_local_auth_config_source_mut() { diff --git a/crates/shirabe/src/util/git.rs b/crates/shirabe/src/util/git.rs index 5923917..d66751c 100644 --- a/crates/shirabe/src/util/git.rs +++ b/crates/shirabe/src/util/git.rs @@ -176,11 +176,8 @@ impl Git { let mut status: i64 = 0; for (counter, callable) in command_callables.iter().enumerate() { let cmd = callable(url_arg); - *last_cmd = PhpMixed::List( - cmd.iter() - .map(|s| Box::new(PhpMixed::String(s.clone()))) - .collect(), - ); + *last_cmd = + PhpMixed::List(cmd.iter().map(|s| PhpMixed::String(s.clone())).collect()); let mut local_output = String::new(); let exec_cwd = if initial_clone && counter == 0 { None @@ -324,7 +321,7 @@ impl Git { &PhpMixed::List( protocols_list .iter() - .map(|s| Box::new(PhpMixed::String(s.clone()))) + .map(|s| PhpMixed::String(s.clone())) .collect(), ), true, @@ -1321,11 +1318,11 @@ impl Git { if in_array( PhpMixed::String(credential.clone()), &PhpMixed::List(vec![ - Box::new(PhpMixed::String("private-token".to_string())), - Box::new(PhpMixed::String("x-token-auth".to_string())), - Box::new(PhpMixed::String("oauth2".to_string())), - Box::new(PhpMixed::String("gitlab-ci-token".to_string())), - Box::new(PhpMixed::String("x-oauth-basic".to_string())), + PhpMixed::String("private-token".to_string()), + PhpMixed::String("x-token-auth".to_string()), + PhpMixed::String("oauth2".to_string()), + PhpMixed::String("gitlab-ci-token".to_string()), + PhpMixed::String("x-oauth-basic".to_string()), ]), false, ) { diff --git a/crates/shirabe/src/util/gitlab.rs b/crates/shirabe/src/util/gitlab.rs index 86b7620..71ff7e3 100644 --- a/crates/shirabe/src/util/gitlab.rs +++ b/crates/shirabe/src/util/gitlab.rs @@ -123,10 +123,10 @@ impl GitLab { if let Some(map) = auth_tokens.as_array() { if let Some(t) = map.get(origin_url) { - token = Some(*t.clone()); + token = Some(t.clone()); } if let Some(t) = map.get(bc_origin_url.as_str()) { - token = Some(*t.clone()); + token = Some(t.clone()); } } @@ -439,34 +439,23 @@ impl GitLab { "", "&", ); - let mut http_inner: IndexMap> = IndexMap::new(); - http_inner.insert( - "method".to_string(), - Box::new(PhpMixed::String("POST".to_string())), - ); + let mut http_inner: IndexMap = IndexMap::new(); + http_inner.insert("method".to_string(), PhpMixed::String("POST".to_string())); http_inner.insert( "header".to_string(), - Box::new(PhpMixed::List( - headers - .into_iter() - .map(|h| Box::new(PhpMixed::String(h))) - .collect(), - )), + PhpMixed::List(headers.into_iter().map(PhpMixed::String).collect()), ); - http_inner.insert("content".to_string(), Box::new(PhpMixed::String(data))); - let mut options: IndexMap> = IndexMap::new(); - options.insert( - "retry-auth-failure".to_string(), - Box::new(PhpMixed::Bool(false)), - ); - options.insert("http".to_string(), Box::new(PhpMixed::Array(http_inner))); + http_inner.insert("content".to_string(), PhpMixed::String(data)); + let mut options: IndexMap = IndexMap::new(); + options.insert("retry-auth-failure".to_string(), PhpMixed::Bool(false)); + options.insert("http".to_string(), PhpMixed::Array(http_inner)); let token = self .http_downloader .borrow_mut() .get( &format!("{}://{}/oauth/token", scheme, api_url), - options.into_iter().map(|(k, v)| (k, *v)).collect(), + options.into_iter().collect(), )? .decode_json()?; @@ -522,34 +511,23 @@ impl GitLab { "", "&", ); - let mut http_inner: IndexMap> = IndexMap::new(); - http_inner.insert( - "method".to_string(), - Box::new(PhpMixed::String("POST".to_string())), - ); + let mut http_inner = IndexMap::new(); + http_inner.insert("method".to_string(), PhpMixed::String("POST".to_string())); http_inner.insert( "header".to_string(), - Box::new(PhpMixed::List( - headers - .into_iter() - .map(|h| Box::new(PhpMixed::String(h))) - .collect(), - )), - ); - http_inner.insert("content".to_string(), Box::new(PhpMixed::String(data))); - let mut options: IndexMap> = IndexMap::new(); - options.insert( - "retry-auth-failure".to_string(), - Box::new(PhpMixed::Bool(false)), + PhpMixed::List(headers.into_iter().map(PhpMixed::String).collect()), ); - options.insert("http".to_string(), Box::new(PhpMixed::Array(http_inner))); + http_inner.insert("content".to_string(), PhpMixed::String(data)); + let mut options: IndexMap = IndexMap::new(); + options.insert("retry-auth-failure".to_string(), PhpMixed::Bool(false)); + options.insert("http".to_string(), PhpMixed::Array(http_inner)); let token = self .http_downloader .borrow_mut() .get( &format!("{}://{}/oauth/token", scheme, origin_url), - options.into_iter().map(|(k, v)| (k, *v)).collect(), + options.into_iter().collect(), )? .decode_json()?; @@ -587,18 +565,15 @@ impl GitLab { .and_then(|v| v.as_string()) .unwrap_or("") .to_string(); - let mut setting: IndexMap> = IndexMap::new(); + let mut setting = IndexMap::new(); setting.insert( "expires-at".to_string(), - Box::new(PhpMixed::Int(created_at + expires_in)), - ); - setting.insert( - "refresh-token".to_string(), - Box::new(PhpMixed::String(refresh_token)), + PhpMixed::Int(created_at + expires_in), ); + setting.insert("refresh-token".to_string(), PhpMixed::String(refresh_token)); setting.insert( "token".to_string(), - Box::new(PhpMixed::String(access_token.to_string())), + PhpMixed::String(access_token.to_string()), ); PhpMixed::Array(setting) } diff --git a/crates/shirabe/src/util/http/curl_downloader.rs b/crates/shirabe/src/util/http/curl_downloader.rs index c03da7a..42153eb 100644 --- a/crates/shirabe/src/util/http/curl_downloader.rs +++ b/crates/shirabe/src/util/http/curl_downloader.rs @@ -143,12 +143,12 @@ impl CurlDownloader { version .as_ref() .and_then(|v| v.get("version")) - .map(|b| (**b).clone()) + .cloned() .unwrap_or(PhpMixed::Null), &PhpMixed::List( BAD_MULTIPLEXING_CURL_VERSIONS .iter() - .map(|s| Box::new(PhpMixed::String((*s).to_string()))) + .map(|s| PhpMixed::String((*s).to_string())) .collect(), ), true, @@ -291,21 +291,11 @@ impl CurlDownloader { m }; let merged = array_merge( - PhpMixed::Array( - defaults - .into_iter() - .map(|(k, v)| (k, Box::new(v))) - .collect(), - ), - PhpMixed::Array( - attributes - .into_iter() - .map(|(k, v)| (k, Box::new(v))) - .collect(), - ), + PhpMixed::Array(defaults.into_iter().collect()), + PhpMixed::Array(attributes.into_iter().collect()), ); let mut attributes: IndexMap = match merged { - PhpMixed::Array(a) => a.into_iter().map(|(k, v)| (k, *v)).collect(), + PhpMixed::Array(a) => a, _ => IndexMap::new(), }; @@ -401,13 +391,13 @@ impl CurlDownloader { PhpMixed::Int(CURLPROTO_HTTP | CURLPROTO_HTTPS), ); - if attributes.get("ipResolve").and_then(|v| v.as_int()) == Some(4) { + if attributes.get("ipResolve").and_then(PhpMixed::as_int) == Some(4) { curl_setopt( &curl_handle, CURLOPT_IPRESOLVE, PhpMixed::Int(CURL_IPRESOLVE_V4), ); - } else if attributes.get("ipResolve").and_then(|v| v.as_int()) == Some(6) { + } else if attributes.get("ipResolve").and_then(PhpMixed::as_int) == Some(6) { curl_setopt( &curl_handle, CURLOPT_IPRESOLVE, @@ -433,31 +423,25 @@ impl CurlDownloader { .entry("http".to_string()) .or_insert(PhpMixed::Array(IndexMap::new())); if let PhpMixed::Array(a) = http { - a.insert("header".to_string(), Box::new(PhpMixed::List(Vec::new()))); + a.insert("header".to_string(), PhpMixed::List(Vec::new())); } } // $options['http']['header'] = array_diff($options['http']['header'], ['Connection: close']); // $options['http']['header'][] = 'Connection: keep-alive'; if let Some(PhpMixed::Array(http)) = options.get_mut("http") - && let Some(boxed) = http.get_mut("header") - && let PhpMixed::List(list) = boxed.as_mut() + && let Some(PhpMixed::List(list)) = http.get_mut("header") { let headers: Vec = list .iter() - .filter_map(|b| match b.as_ref() { + .filter_map(|b| match b { PhpMixed::String(s) => Some(s.clone()), _ => None, }) .collect(); let diffed = array_diff(&headers, &["Connection: close".to_string()]); - let mut new_list: Vec> = diffed - .into_iter() - .map(|s| Box::new(PhpMixed::String(s))) - .collect(); - new_list.push(Box::new(PhpMixed::String( - "Connection: keep-alive".to_string(), - ))); + let mut new_list: Vec = diffed.into_iter().map(PhpMixed::String).collect(); + new_list.push(PhpMixed::String("Connection: keep-alive".to_string())); *list = new_list; } @@ -515,11 +499,11 @@ impl CurlDownloader { version .as_ref() .and_then(|v| v.get("version")) - .map(|b| (**b).clone()) + .cloned() .unwrap_or(PhpMixed::Null), &PhpMixed::List(vec![ - Box::new(PhpMixed::String("8.7.0".to_string())), - Box::new(PhpMixed::String("8.7.1".to_string())), + PhpMixed::String("8.7.0".to_string()), + PhpMixed::String("8.7.1".to_string()), ]), true, ) @@ -552,7 +536,7 @@ impl CurlDownloader { .get(&r#type) .and_then(|v| v.as_array()) .and_then(|a| a.get(name)) - .map(|b| (**b).clone()) + .cloned() .unwrap_or(PhpMixed::Null); let to_set = if matches!(val, PhpMixed::Bool(true)) { PhpMixed::Int(2) @@ -565,7 +549,7 @@ impl CurlDownloader { .get(&r#type) .and_then(|v| v.as_array()) .and_then(|a| a.get(name)) - .map(|b| (**b).clone()) + .cloned() .unwrap_or(PhpMixed::Null); curl_setopt(&curl_handle, *curl_option, val); } @@ -576,7 +560,7 @@ impl CurlDownloader { let ssl_options: IndexMap = options .get("ssl") .and_then(|v| v.as_array()) - .map(|a| a.iter().map(|(k, v)| (k.clone(), (**v).clone())).collect()) + .map(|a| a.iter().map(|(k, v)| (k.clone(), v.clone())).collect()) .unwrap_or_else(IndexMap::new); let proxy_curl_options = proxy .get_curl_options(&ssl_options) @@ -585,7 +569,7 @@ impl CurlDownloader { let progress = array_diff_key( match curl_getinfo(&curl_handle) { - PhpMixed::Array(a) => a.into_iter().map(|(k, v)| (k, *v)).collect(), + PhpMixed::Array(a) => a, _ => IndexMap::new(), }, &time_info_static() @@ -599,33 +583,10 @@ impl CurlDownloader { job.insert("origin".to_string(), PhpMixed::String(origin.to_string())); job.insert( "attributes".to_string(), - PhpMixed::Array( - attributes - .clone() - .into_iter() - .map(|(k, v)| (k, Box::new(v))) - .collect(), - ), - ); - job.insert( - "options".to_string(), - PhpMixed::Array( - original_options - .into_iter() - .map(|(k, v)| (k, Box::new(v))) - .collect(), - ), - ); - job.insert( - "progress".to_string(), - PhpMixed::Array( - progress - .clone() - .into_iter() - .map(|(k, v)| (k, Box::new(v))) - .collect(), - ), + PhpMixed::Array(attributes.clone()), ); + job.insert("options".to_string(), PhpMixed::Array(original_options)); + job.insert("progress".to_string(), PhpMixed::Array(progress.clone())); // curlHandle, headerHandle, bodyHandle, resolve, reject are PHP resources/callables; // stored as opaque PhpMixed::Null placeholders (real values live in Rust-side fields). // TODO(phase-c): storing the real \CurlHandle and the resolve/reject callables needs the @@ -659,10 +620,10 @@ impl CurlDownloader { .get("http") .and_then(|v| v.as_array()) .and_then(|a| a.get("header")) - .and_then(|b| match b.as_ref() { + .and_then(|b| match b { PhpMixed::List(l) => Some( l.iter() - .filter_map(|x| match x.as_ref() { + .filter_map(|x| match x { PhpMixed::String(s) => Some(s.clone()), _ => None, }) @@ -743,15 +704,13 @@ impl CurlDownloader { loop { let progress_read = curl_multi_info_read(&self.multi_handle); - let mut progress: IndexMap> = match &progress_read { + let mut progress: IndexMap = match &progress_read { PhpMixed::Array(a) => a.clone(), _ => break, }; // $curlHandle = $progress['handle']; $result = $progress['result']; $i = (int) $curlHandle; - let _curl_handle_placeholder: PhpMixed = progress - .get("handle") - .map(|b| (**b).clone()) - .unwrap_or(PhpMixed::Null); + let _curl_handle_placeholder: PhpMixed = + progress.get("handle").cloned().unwrap_or(PhpMixed::Null); let result_code: i64 = progress.get("result").and_then(|b| b.as_int()).unwrap_or(0); // TODO(phase-c): the job id is `(int) $progress['handle']` — the integer id of the // \CurlHandle reported by curl_multi_info_read. Recovering it needs real curl handle @@ -809,7 +768,7 @@ impl CurlDownloader { if error.is_empty() && function_exists("curl_strerror") { error = curl_strerror(errno).unwrap_or_default(); } - progress.insert("error_code".to_string(), Box::new(PhpMixed::Int(errno))); + progress.insert("error_code".to_string(), PhpMixed::Int(errno)); if errno == 28 /* CURLE_OPERATION_TIMEDOUT */ && PHP_VERSION_ID >= 70300 @@ -846,18 +805,18 @@ impl CurlDownloader { && (in_array( PhpMixed::Int(errno), &PhpMixed::List(vec![ - Box::new(PhpMixed::Int(7 /* CURLE_COULDNT_CONNECT */)), - Box::new(PhpMixed::Int(16 /* CURLE_HTTP2 */)), - Box::new(PhpMixed::Int(92 /* CURLE_HTTP2_STREAM */)), - Box::new(PhpMixed::Int(6 /* CURLE_COULDNT_RESOLVE_HOST */)), - Box::new(PhpMixed::Int(28 /* CURLE_OPERATION_TIMEDOUT */)), + PhpMixed::Int(7 /* CURLE_COULDNT_CONNECT */), + PhpMixed::Int(16 /* CURLE_HTTP2 */), + PhpMixed::Int(92 /* CURLE_HTTP2_STREAM */), + PhpMixed::Int(6 /* CURLE_COULDNT_RESOLVE_HOST */), + PhpMixed::Int(28 /* CURLE_OPERATION_TIMEDOUT */), ]), true, ) || (in_array( PhpMixed::Int(errno), &PhpMixed::List(vec![ - Box::new(PhpMixed::Int(56 /* CURLE_RECV_ERROR */)), - Box::new(PhpMixed::Int(35 /* CURLE_SSL_CONNECT_ERROR */)), + PhpMixed::Int(56 /* CURLE_RECV_ERROR */), + PhpMixed::Int(35 /* CURLE_SSL_CONNECT_ERROR */), ]), true, ) && str_contains(&error, "Connection reset by peer"))) @@ -1011,7 +970,7 @@ impl CurlDownloader { .as_ref() .unwrap() .iter() - .map(|s| Box::new(PhpMixed::String(s.clone()))) + .map(|s| PhpMixed::String(s.clone())) .collect() ), true @@ -1046,10 +1005,7 @@ impl CurlDownloader { status_code, headers.clone().unwrap_or_default(), contents.as_string().map(|s| s.to_string()), - progress - .iter() - .map(|(k, v)| (k.clone(), (**v).clone())) - .collect(), + progress.clone(), )); self.io.write_error3( &format!( @@ -1113,10 +1069,7 @@ impl CurlDownloader { status_code, headers.clone().unwrap_or_default(), contents.as_string().map(|s| s.to_string()), - progress - .iter() - .map(|(k, v)| (k.clone(), (**v).clone())) - .collect(), + progress.clone(), )); self.io.write_error3( &format!( @@ -1144,7 +1097,7 @@ impl CurlDownloader { self.io.clone(), job.get("origin").and_then(|v| v.as_string()).unwrap_or(""), &match json_decode(response_ref.inner.get_body().unwrap_or(""), true)? { - PhpMixed::Array(a) => a.into_iter().map(|(k, v)| (k, *v)).collect(), + PhpMixed::Array(a) => a, _ => IndexMap::new(), }, )?; @@ -1241,14 +1194,14 @@ impl CurlDownloader { && in_array( PhpMixed::Int(sc), &PhpMixed::List(vec![ - Box::new(PhpMixed::Int(423)), - Box::new(PhpMixed::Int(425)), - Box::new(PhpMixed::Int(500)), - Box::new(PhpMixed::Int(502)), - Box::new(PhpMixed::Int(503)), - Box::new(PhpMixed::Int(504)), - Box::new(PhpMixed::Int(507)), - Box::new(PhpMixed::Int(510)), + PhpMixed::Int(423), + PhpMixed::Int(425), + PhpMixed::Int(500), + PhpMixed::Int(502), + PhpMixed::Int(503), + PhpMixed::Int(504), + PhpMixed::Int(507), + PhpMixed::Int(510), ]), true, ) @@ -1312,14 +1265,14 @@ impl CurlDownloader { job.get("attributes") .and_then(|v| v.as_array()) .and_then(|a| a.get("storeAuth")) - .map(|b| (**b).clone()), + .cloned(), Some(PhpMixed::Bool(false)) ) { let store_auth_val = job .get("attributes") .and_then(|v| v.as_array()) .and_then(|a| a.get("storeAuth")) - .map(|b| (**b).clone()) + .cloned() .unwrap_or(PhpMixed::Bool(false)); let store_auth = match store_auth_val { PhpMixed::Bool(b) => StoreAuth::Bool(b), @@ -1356,12 +1309,7 @@ impl CurlDownloader { if let Some(r) = &response { e.set_response(r.inner.get_body().map(|s| s.to_string())); } - e.set_response_info( - progress - .iter() - .map(|(_, v)| (**v).clone()) - .collect::>(), - ); + e.set_response_info(progress.values().cloned().collect::>()); self.reject_job(&job, anyhow::anyhow!(e.message)); } Err(e) => { @@ -1377,7 +1325,7 @@ impl CurlDownloader { // $progress = array_diff_key(curl_getinfo($curlHandle), self::$timeInfo); let progress_now = array_diff_key( match curl_getinfo(/* TODO real handle */ &curl_init()) { - PhpMixed::Array(a) => a.into_iter().map(|(k, v)| (k, *v)).collect(), + PhpMixed::Array(a) => a, _ => IndexMap::new(), }, &time_info_static() @@ -1392,21 +1340,16 @@ impl CurlDownloader { .and_then(|j| j.get("progress")) .cloned() .unwrap_or(PhpMixed::Null); - let prev_progress_map = match &prev_progress { - PhpMixed::Array(a) => a.clone(), + let prev_progress_map: IndexMap = match prev_progress { + PhpMixed::Array(a) => a, _ => IndexMap::new(), }; - let progress_now_boxed: IndexMap> = progress_now - .clone() - .into_iter() - .map(|(k, v)| (k, Box::new(v))) - .collect(); - if !maps_equal(&prev_progress_map, &progress_now_boxed) { + if !maps_equal(&prev_progress_map, &progress_now) { if let Some(job) = self.jobs.get_mut(&i) { job.insert( "progress".to_string(), - PhpMixed::Array(progress_now_boxed.clone()), + PhpMixed::Array(progress_now.clone()), ); } @@ -1614,10 +1557,7 @@ impl CurlDownloader { ) -> anyhow::Result> { if in_array( PhpMixed::Int(response.inner.get_status_code()), - &PhpMixed::List(vec![ - Box::new(PhpMixed::Int(401)), - Box::new(PhpMixed::Int(403)), - ]), + &PhpMixed::List(vec![PhpMixed::Int(401), PhpMixed::Int(403)]), false, ) && job .get("attributes") @@ -1675,7 +1615,7 @@ impl CurlDownloader { // check for gitlab 404 when downloading archives let gitlab_domains = self.config.borrow_mut().get("gitlab-domains"); - let gitlab_domains_list: Vec> = match gitlab_domains { + let gitlab_domains_list: Vec = match gitlab_domains { PhpMixed::List(l) => l, _ => Vec::new(), }; @@ -1754,15 +1694,10 @@ impl CurlDownloader { }; let merged = array_merge( PhpMixed::Array(job_attrs), - PhpMixed::Array( - attributes - .into_iter() - .map(|(k, v)| (k, Box::new(v))) - .collect(), - ), + PhpMixed::Array(attributes.into_iter().collect()), ); let attributes: IndexMap = match merged { - PhpMixed::Array(a) => a.into_iter().map(|(k, v)| (k, *v)).collect(), + PhpMixed::Array(a) => a, _ => IndexMap::new(), }; let origin = Url::get_origin(&self.config.borrow(), url); @@ -1772,7 +1707,7 @@ impl CurlDownloader { .and_then(|v| v.as_string()) .map(|s| s.to_string()); let options = match job.get("options") { - Some(PhpMixed::Array(a)) => a.iter().map(|(k, v)| (k.clone(), (**v).clone())).collect(), + Some(PhpMixed::Array(a)) => a.clone(), _ => IndexMap::new(), }; // PHP forwards the original job's resolve/reject callables into the restarted download. @@ -1836,10 +1771,8 @@ impl CurlDownloader { .to_lowercase(), ), &PhpMixed::List(vec![ - Box::new(PhpMixed::String("application/json".to_string())), - Box::new(PhpMixed::String( - "application/json; charset=utf-8".to_string(), - )), + PhpMixed::String("application/json".to_string()), + PhpMixed::String("application/json; charset=utf-8".to_string()), ]), true, ) { @@ -1907,7 +1840,7 @@ impl CurlDownloader { } } -fn maps_equal(a: &IndexMap>, b: &IndexMap>) -> bool { +fn maps_equal(a: &IndexMap, b: &IndexMap) -> bool { if a.len() != b.len() { return false; } diff --git a/crates/shirabe/src/util/http_downloader.rs b/crates/shirabe/src/util/http_downloader.rs index 929dd67..d5d619d 100644 --- a/crates/shirabe/src/util/http_downloader.rs +++ b/crates/shirabe/src/util/http_downloader.rs @@ -454,7 +454,7 @@ impl HttpDownloader { _ => None, }) .cloned(); - if let Some(PhpMixed::List(list)) = http_header.as_deref() { + if let Some(PhpMixed::List(list)) = http_header.as_ref() { let joined = implode( "", &list @@ -463,7 +463,7 @@ impl HttpDownloader { .collect::>(), ); stripos(&joined, "if-modified-since").is_some() - } else if let Some(PhpMixed::Array(m)) = http_header.as_deref() { + } else if let Some(PhpMixed::Array(m)) = http_header.as_ref() { let joined = implode( "", &m.values() @@ -718,7 +718,7 @@ impl HttpDownloader { if let Some(PhpMixed::List(list)) = entry { for spec in list { let r#type = substr(key, 0, Some(-1)); - if let PhpMixed::Array(spec_map) = spec.as_ref() { + if let PhpMixed::Array(spec_map) = spec { let constraint = version_parser.parse_constraints( spec_map .get("versions") @@ -769,15 +769,12 @@ impl HttpDownloader { { Silencer::suppress(None); let mut ctx_options: IndexMap = IndexMap::new(); - let mut ssl_map: IndexMap> = IndexMap::new(); - ssl_map.insert("verify_peer".to_string(), Box::new(PhpMixed::Bool(false))); + let mut ssl_map: IndexMap = IndexMap::new(); + ssl_map.insert("verify_peer".to_string(), PhpMixed::Bool(false)); ctx_options.insert("ssl".to_string(), PhpMixed::Array(ssl_map)); - let mut http_map: IndexMap> = IndexMap::new(); - http_map.insert( - "follow_location".to_string(), - Box::new(PhpMixed::Bool(false)), - ); - http_map.insert("ignore_errors".to_string(), Box::new(PhpMixed::Bool(true))); + let mut http_map: IndexMap = IndexMap::new(); + http_map.insert("follow_location".to_string(), PhpMixed::Bool(false)); + http_map.insert("ignore_errors".to_string(), PhpMixed::Bool(true)); ctx_options.insert("http".to_string(), PhpMixed::Array(http_map)); // TODO(phase-c): file_get_contents only takes a path; the stream context arg is dropped // until the PHP stream-context layer is modeled. diff --git a/crates/shirabe/src/util/no_proxy_pattern.rs b/crates/shirabe/src/util/no_proxy_pattern.rs index 34491ba..ed93414 100644 --- a/crates/shirabe/src/util/no_proxy_pattern.rs +++ b/crates/shirabe/src/util/no_proxy_pattern.rs @@ -489,7 +489,7 @@ impl NoProxyPattern { inner.insert("max_range".to_string(), PhpMixed::Int(max)); options.insert( "options".to_string(), - PhpMixed::Array(inner.into_iter().map(|(k, v)| (k, Box::new(v))).collect()), + PhpMixed::Array(inner.into_iter().collect()), ); !matches!( diff --git a/crates/shirabe/src/util/perforce.rs b/crates/shirabe/src/util/perforce.rs index 3f73f7d..0d56afb 100644 --- a/crates/shirabe/src/util/perforce.rs +++ b/crates/shirabe/src/util/perforce.rs @@ -146,10 +146,7 @@ impl Perforce { let use_p4_client = false; let command = self.generate_p4_command(task, use_p4_client); self.execute_command(PhpMixed::List( - command - .into_iter() - .map(|s| Box::new(PhpMixed::String(s))) - .collect(), + command.into_iter().map(PhpMixed::String).collect(), )); let client_spec = self.get_p4_client_spec(); let file_system = self.get_filesystem(); @@ -358,10 +355,7 @@ impl Perforce { pub fn is_logged_in(&mut self) -> Result { let command = self.generate_p4_command(vec!["login".to_string(), "-s".to_string()], false); let exit_code = self.execute_command(PhpMixed::List( - command - .into_iter() - .map(|s| Box::new(PhpMixed::String(s))) - .collect(), + command.into_iter().map(PhpMixed::String).collect(), )); if exit_code != 0 { let error_output = self.process.borrow().get_error_output().to_string(); @@ -411,10 +405,7 @@ impl Perforce { p4_sync_command.push(format!("@{}", source_reference)); } self.execute_command(PhpMixed::List( - p4_sync_command - .into_iter() - .map(|s| Box::new(PhpMixed::String(s))) - .collect(), + p4_sync_command.into_iter().map(PhpMixed::String).collect(), )); chdir(&prev_dir); @@ -592,7 +583,7 @@ impl Perforce { let decoded = json_decode(&composer_file_content, true)?; Ok(match decoded { - PhpMixed::Array(m) => Some(m.into_iter().map(|(k, v)| (k, *v)).collect()), + PhpMixed::Array(m) => Some(m.into_iter().collect()), _ => None, }) } @@ -602,10 +593,7 @@ impl Perforce { let command = self.generate_p4_command(vec!["print".to_string(), path], true); self.execute_command(PhpMixed::List( - command - .into_iter() - .map(|s| Box::new(PhpMixed::String(s))) - .collect(), + command.into_iter().map(PhpMixed::String).collect(), )); let result = self.command_result.clone(); @@ -631,10 +619,7 @@ impl Perforce { ); let command = self.generate_p4_command(vec!["files".to_string(), path], false); self.execute_command(PhpMixed::List( - command - .into_iter() - .map(|s| Box::new(PhpMixed::String(s))) - .collect(), + command.into_iter().map(PhpMixed::String).collect(), )); let result = self.command_result.clone(); let index2 = strpos(&result, "no such file(s)."); @@ -673,10 +658,7 @@ impl Perforce { true, ); self.execute_command(PhpMixed::List( - command - .into_iter() - .map(|s| Box::new(PhpMixed::String(s))) - .collect(), + command.into_iter().map(PhpMixed::String).collect(), )); let result = self.command_result.clone(); let res_array = explode(PHP_EOL, &result); @@ -698,10 +680,7 @@ impl Perforce { false, ); self.execute_command(PhpMixed::List( - command - .into_iter() - .map(|s| Box::new(PhpMixed::String(s))) - .collect(), + command.into_iter().map(PhpMixed::String).collect(), )); let result = self.command_result.clone(); let res_array = explode(PHP_EOL, &result); @@ -728,10 +707,7 @@ impl Perforce { pub fn get_tags(&mut self) -> IndexMap { let command = self.generate_p4_command(vec!["labels".to_string()], true); self.execute_command(PhpMixed::List( - command - .into_iter() - .map(|s| Box::new(PhpMixed::String(s))) - .collect(), + command.into_iter().map(PhpMixed::String).collect(), )); let result = self.command_result.clone(); let res_array = explode(PHP_EOL, &result); @@ -751,10 +727,7 @@ impl Perforce { pub fn check_stream(&mut self) -> bool { let command = self.generate_p4_command(vec!["depots".to_string()], false); self.execute_command(PhpMixed::List( - command - .into_iter() - .map(|s| Box::new(PhpMixed::String(s))) - .collect(), + command.into_iter().map(PhpMixed::String).collect(), )); let result = self.command_result.clone(); let res_array = explode(PHP_EOL, &result); @@ -783,10 +756,7 @@ impl Perforce { let command = self.generate_p4_command(vec!["changes".to_string(), "-m1".to_string(), label], true); self.execute_command(PhpMixed::List( - command - .into_iter() - .map(|s| Box::new(PhpMixed::String(s))) - .collect(), + command.into_iter().map(PhpMixed::String).collect(), )); let changes = self.command_result.clone(); if strpos(&changes, "Change") != Some(0) { @@ -811,10 +781,7 @@ impl Perforce { true, ); self.execute_command(PhpMixed::List( - command - .into_iter() - .map(|s| Box::new(PhpMixed::String(s))) - .collect(), + command.into_iter().map(PhpMixed::String).collect(), )); Some(self.command_result.clone()) diff --git a/crates/shirabe/src/util/platform.rs b/crates/shirabe/src/util/platform.rs index 7560072..449874e 100644 --- a/crates/shirabe/src/util/platform.rs +++ b/crates/shirabe/src/util/platform.rs @@ -304,8 +304,8 @@ impl Platform { if in_array( PhpMixed::String(strtoupper(&Self::get_env("MSYSTEM").unwrap_or_default())), &PhpMixed::List(vec![ - Box::new(PhpMixed::String("MINGW32".to_string())), - Box::new(PhpMixed::String("MINGW64".to_string())), + PhpMixed::String("MINGW32".to_string()), + PhpMixed::String("MINGW64".to_string()), ]), true, ) { diff --git a/crates/shirabe/src/util/process_executor.rs b/crates/shirabe/src/util/process_executor.rs index ca31290..2bdf065 100644 --- a/crates/shirabe/src/util/process_executor.rs +++ b/crates/shirabe/src/util/process_executor.rs @@ -149,7 +149,7 @@ impl ProcessExecutor { let cmd = PhpMixed::List( command .iter() - .map(|s| Box::new(PhpMixed::String(s.clone()))) + .map(|s| PhpMixed::String(s.clone())) .collect(), ); let mut buf = PhpMixed::String(String::new()); @@ -352,9 +352,9 @@ impl ProcessExecutor { git_env.insert("GIT_DIR".to_string(), cwd.unwrap().to_string()); self.run_process( PhpMixed::List(vec![ - Box::new(PhpMixed::String("git".to_string())), - Box::new(PhpMixed::String("config".to_string())), - Box::new(PhpMixed::String("safe.bareRepository".to_string())), + PhpMixed::String("git".to_string()), + PhpMixed::String("config".to_string()), + PhpMixed::String("safe.bareRepository".to_string()), ]), cwd, Some(git_env.clone()), @@ -677,7 +677,7 @@ impl ProcessExecutor { } else if let PhpMixed::List(list) = command { let parts: Vec = array_map( |v| Self::escape(v.as_string().unwrap_or("")), - &list.iter().map(|b| (**b).clone()).collect::>(), + &list.iter().cloned().collect::>(), ); implode(" ", &parts) } else { @@ -810,7 +810,7 @@ impl ProcessExecutor { &PhpMixed::List( Self::BUILTIN_CMD_COMMANDS .iter() - .map(|s| Box::new(PhpMixed::String(s.to_string()))) + .map(|s| PhpMixed::String(s.to_string())) .collect(), ), true, @@ -870,21 +870,13 @@ impl IntoExecCommand for &String { impl IntoExecCommand for Vec { fn into_exec_command(self) -> PhpMixed { - PhpMixed::List( - self.into_iter() - .map(|s| Box::new(PhpMixed::String(s))) - .collect(), - ) + PhpMixed::List(self.into_iter().map(PhpMixed::String).collect()) } } impl IntoExecCommand for &Vec { fn into_exec_command(self) -> PhpMixed { - PhpMixed::List( - self.iter() - .map(|s| Box::new(PhpMixed::String(s.clone()))) - .collect(), - ) + PhpMixed::List(self.iter().map(|s| PhpMixed::String(s.clone())).collect()) } } @@ -892,7 +884,7 @@ impl IntoExecCommand for &[&str; N] { fn into_exec_command(self) -> PhpMixed { PhpMixed::List( self.iter() - .map(|s| Box::new(PhpMixed::String(s.to_string()))) + .map(|s| PhpMixed::String(s.to_string())) .collect(), ) } @@ -902,7 +894,7 @@ impl IntoExecCommand for &[&str] { fn into_exec_command(self) -> PhpMixed { PhpMixed::List( self.iter() - .map(|s| Box::new(PhpMixed::String(s.to_string()))) + .map(|s| PhpMixed::String(s.to_string())) .collect(), ) } @@ -910,11 +902,7 @@ impl IntoExecCommand for &[&str] { impl IntoExecCommand for &[String] { fn into_exec_command(self) -> PhpMixed { - PhpMixed::List( - self.iter() - .map(|s| Box::new(PhpMixed::String(s.clone()))) - .collect(), - ) + PhpMixed::List(self.iter().map(|s| PhpMixed::String(s.clone())).collect()) } } diff --git a/crates/shirabe/src/util/remote_filesystem.rs b/crates/shirabe/src/util/remote_filesystem.rs index 1890a95..c4b3923 100644 --- a/crates/shirabe/src/util/remote_filesystem.rs +++ b/crates/shirabe/src/util/remote_filesystem.rs @@ -234,7 +234,7 @@ impl RemoteFilesystem { if let Some(http_opts) = options.get_mut("http") && let PhpMixed::Array(m) = http_opts { - m.insert("ignore_errors".to_string(), Box::new(PhpMixed::Bool(true))); + m.insert("ignore_errors".to_string(), PhpMixed::Bool(true)); } let mut degraded_packagist = false; @@ -331,7 +331,7 @@ impl RemoteFilesystem { .map(|s| json_decode(s, true).unwrap_or(PhpMixed::Null)) .unwrap_or(PhpMixed::Null); let parsed_map: IndexMap = match parsed { - PhpMixed::Array(m) => m.into_iter().map(|(k, v)| (k, *v)).collect(), + PhpMixed::Array(m) => m.into_iter().collect(), _ => IndexMap::new(), }; let _ = HttpDownloader::output_warnings( @@ -854,10 +854,7 @@ impl RemoteFilesystem { .entry("http".to_string()) .or_insert_with(|| PhpMixed::Array(IndexMap::new())); if let PhpMixed::Array(m) = http_entry { - m.insert( - "protocol_version".to_string(), - Box::new(PhpMixed::Float(1.1)), - ); + m.insert("protocol_version".to_string(), PhpMixed::Float(1.1)); } headers.push("Connection: close".to_string()); } @@ -866,7 +863,7 @@ impl RemoteFilesystem { .get("http") .and_then(|v| v.as_array()) .and_then(|m| m.get("header")) - .map(|v| matches!(v.as_ref(), PhpMixed::String(_))) + .map(|v| matches!(v, PhpMixed::String(_))) .unwrap_or(false); if header_is_string { let header_str = options["http"].as_array().unwrap()["header"] @@ -877,12 +874,7 @@ impl RemoteFilesystem { if let Some(PhpMixed::Array(m)) = options.get_mut("http") { m.insert( "header".to_string(), - Box::new(PhpMixed::List( - split - .into_iter() - .map(|s| Box::new(PhpMixed::String(s))) - .collect(), - )), + PhpMixed::List(split.into_iter().map(PhpMixed::String).collect()), ); } } @@ -896,16 +888,16 @@ impl RemoteFilesystem { .entry("http".to_string()) .or_insert_with(|| PhpMixed::Array(IndexMap::new())); if let PhpMixed::Array(m) = http_entry { - m.insert("follow_location".to_string(), Box::new(PhpMixed::Int(0))); + m.insert("follow_location".to_string(), PhpMixed::Int(0)); } for header in headers { if let Some(PhpMixed::Array(m)) = options.get_mut("http") { let header_list = m .entry("header".to_string()) - .or_insert_with(|| Box::new(PhpMixed::List(Vec::new()))); - if let PhpMixed::List(l) = header_list.as_mut() { - l.push(Box::new(PhpMixed::String(header))); + .or_insert_with(|| PhpMixed::List(Vec::new())); + if let PhpMixed::List(l) = header_list { + l.push(PhpMixed::String(header)); } } } diff --git a/crates/shirabe/src/util/stream_context_factory.rs b/crates/shirabe/src/util/stream_context_factory.rs index d73f3b4..db48122 100644 --- a/crates/shirabe/src/util/stream_context_factory.rs +++ b/crates/shirabe/src/util/stream_context_factory.rs @@ -33,7 +33,7 @@ impl StreamContextFactory { let mut o = IndexMap::new(); o.insert( "http".to_string(), - PhpMixed::Array(http.into_iter().map(|(k, v)| (k, Box::new(v))).collect()), + PhpMixed::Array(http.into_iter().collect()), ); o }; @@ -57,12 +57,7 @@ impl StreamContextFactory { let fixed = Self::fix_http_header_field(&header); http.insert( "header".to_string(), - Box::new(PhpMixed::List( - fixed - .into_iter() - .map(|s| Box::new(PhpMixed::String(s))) - .collect(), - )), + PhpMixed::List(fixed.into_iter().map(PhpMixed::String).collect()), ); } @@ -81,24 +76,24 @@ impl StreamContextFactory { .map(|a| a.contains_key("header")) .unwrap_or(false); if !has_header && let Some(PhpMixed::Array(http)) = options.get_mut("http") { - http.insert("header".to_string(), Box::new(PhpMixed::List(vec![]))); + http.insert("header".to_string(), PhpMixed::List(vec![])); } // Convert string header to array let header_is_string = options .get("http") .and_then(|v| v.as_array()) .and_then(|a| a.get("header")) - .map(|v| matches!(**v, PhpMixed::String(_))) + .map(|v| matches!(*v, PhpMixed::String(_))) .unwrap_or(false); if header_is_string && let Some(PhpMixed::Array(http)) = options.get_mut("http") - && let Some(PhpMixed::String(header_str)) = http.get("header").map(|v| *v.clone()) + && let Some(PhpMixed::String(header_str)) = http.get("header").cloned() { - let parts: Vec> = header_str + let parts: Vec = header_str .split("\r\n") - .map(|s| Box::new(PhpMixed::String(s.to_string()))) + .map(|s| PhpMixed::String(s.to_string())) .collect(); - http.insert("header".to_string(), Box::new(PhpMixed::List(parts))); + http.insert("header".to_string(), PhpMixed::List(parts)); } // Add stream proxy options if there is a proxy @@ -135,18 +130,18 @@ impl StreamContextFactory { let proxy_http = proxy_options.get("http"); if let Some(proxy_header) = proxy_http.and_then(|h| h.get("header")) && let Some(PhpMixed::Array(http)) = options.get_mut("http") - && let Some(PhpMixed::List(headers)) = http.get_mut("header").map(|v| &mut **v) + && let Some(PhpMixed::List(headers)) = http.get_mut("header") { - headers.push(Box::new(proxy_header.clone())); + headers.push(proxy_header.clone()); } let proxy_options_flat: IndexMap = proxy_options .iter() .map(|(k, v)| { - let inner: IndexMap> = v + let inner: IndexMap = v .iter() .filter(|(ik, _)| ik.as_str() != "header") - .map(|(ik, iv)| (ik.clone(), Box::new(iv.clone()))) + .map(|(ik, iv)| (ik.clone(), iv.clone())) .collect(); (k.clone(), PhpMixed::Array(inner)) }) @@ -180,8 +175,8 @@ impl StreamContextFactory { .get("http") .and_then(|v| v.as_array()) .and_then(|a| a.get("header")) - .and_then(|v| match **v { - PhpMixed::List(ref list) => { + .and_then(|v| match v { + PhpMixed::List(list) => { let joined: String = list .iter() .filter_map(|item| item.as_string()) @@ -221,9 +216,9 @@ impl StreamContextFactory { }, ); if let Some(PhpMixed::Array(http)) = options.get_mut("http") - && let Some(PhpMixed::List(headers)) = http.get_mut("header").map(|v| &mut **v) + && let Some(PhpMixed::List(headers)) = http.get_mut("header") { - headers.push(Box::new(PhpMixed::String(user_agent))); + headers.push(PhpMixed::String(user_agent)); } } @@ -299,12 +294,7 @@ impl StreamContextFactory { let mut d = IndexMap::new(); d.insert( "ssl".to_string(), - PhpMixed::Array( - ssl_defaults - .into_iter() - .map(|(k, v)| (k, Box::new(v))) - .collect(), - ), + PhpMixed::Array(ssl_defaults.into_iter().collect()), ); d }; @@ -314,18 +304,15 @@ impl StreamContextFactory { { let merged = array_replace_recursive( match ssl_defaults_mixed { - PhpMixed::Array(a) => a.into_iter().map(|(k, v)| (k, *v)).collect(), + PhpMixed::Array(a) => a, _ => IndexMap::new(), }, match ssl_options.clone() { - PhpMixed::Array(a) => a.into_iter().map(|(k, v)| (k, *v)).collect(), + PhpMixed::Array(a) => a, _ => IndexMap::new(), }, ); - defaults.insert( - "ssl".to_string(), - PhpMixed::Array(merged.into_iter().map(|(k, v)| (k, Box::new(v))).collect()), - ); + defaults.insert("ssl".to_string(), PhpMixed::Array(merged)); } // Attempt to find a local cafile or throw an exception if none pre-set. @@ -337,11 +324,11 @@ impl StreamContextFactory { let result = CaBundle::get_system_ca_root_bundle_path(logger); if shirabe_php_shim::is_dir(&result) { if let Some(PhpMixed::Array(ssl)) = defaults.get_mut("ssl") { - ssl.insert("capath".to_string(), Box::new(PhpMixed::String(result))); + ssl.insert("capath".to_string(), PhpMixed::String(result)); } } else { if let Some(PhpMixed::Array(ssl)) = defaults.get_mut("ssl") { - ssl.insert("cafile".to_string(), Box::new(PhpMixed::String(result))); + ssl.insert("cafile".to_string(), PhpMixed::String(result)); } } } @@ -378,10 +365,7 @@ impl StreamContextFactory { // Disable TLS compression to prevent CRIME attacks where supported. if let Some(PhpMixed::Array(ssl)) = defaults.get_mut("ssl") { - ssl.insert( - "disable_compression".to_string(), - Box::new(PhpMixed::Bool(true)), - ); + ssl.insert("disable_compression".to_string(), PhpMixed::Bool(true)); } Ok(defaults) diff --git a/crates/shirabe/src/util/svn.rs b/crates/shirabe/src/util/svn.rs index 269cb5d..319edaf 100644 --- a/crates/shirabe/src/util/svn.rs +++ b/crates/shirabe/src/util/svn.rs @@ -371,7 +371,7 @@ impl Svn { let auth_for_host = auth_config .as_array() .and_then(|m| m.get(host_str)) - .map(|v| (**v).clone()); + .map(|v| v.clone()); if let Some(entry) = auth_for_host && let Some(entry_arr) = entry.as_array() { @@ -408,7 +408,7 @@ impl Svn { }; let user_val = uri_arr .get("user") - .map(|v| (**v).clone()) + .map(|v| v.clone()) .unwrap_or(PhpMixed::Null); if empty(&user_val) { self.has_auth = Some(false); @@ -417,7 +417,7 @@ impl Svn { let pass_val = uri_arr .get("pass") - .map(|v| (**v).clone()) + .map(|v| v.clone()) .unwrap_or(PhpMixed::Null); self.credentials = Some(SvnCredentials { username: user_val.as_string().unwrap_or("").to_string(), -- cgit v1.3.1