summaryrefslogtreecommitdiff
path: root/cli
diff options
context:
space:
mode:
authorMatt Mastracci <matthew@mastracci.com>2024-03-22 14:03:56 -0700
committerGitHub <noreply@github.com>2024-03-22 14:03:56 -0700
commit86cdf3703399367836c89accba3756437d820bb0 (patch)
tree986ab6c88e0a65ffaadb164eab94d44c0ff497b1 /cli
parent08ec6e5831478f6d15188e91d9a8e3c00d80c1ed (diff)
perf(cli): use args_os (#23039)
Extracted from #22718
Diffstat (limited to 'cli')
-rw-r--r--cli/args/flags.rs5
-rw-r--r--cli/lsp/testing/execution.rs2
-rw-r--r--cli/main.rs2
-rw-r--r--cli/mainrt.rs5
-rw-r--r--cli/standalone/binary.rs8
5 files changed, 13 insertions, 9 deletions
diff --git a/cli/args/flags.rs b/cli/args/flags.rs
index 22c7d8e6d..283ebc9a3 100644
--- a/cli/args/flags.rs
+++ b/cli/args/flags.rs
@@ -17,6 +17,7 @@ use deno_runtime::permissions::parse_sys_kind;
use log::debug;
use log::Level;
use std::env;
+use std::ffi::OsString;
use std::net::SocketAddr;
use std::num::NonZeroU32;
use std::num::NonZeroU8;
@@ -909,7 +910,7 @@ To evaluate code in the shell:
);
/// Main entry point for parsing deno's command line flags.
-pub fn flags_from_vec(args: Vec<String>) -> clap::error::Result<Flags> {
+pub fn flags_from_vec(args: Vec<OsString>) -> clap::error::Result<Flags> {
let mut app = clap_root();
let mut matches = app.try_get_matches_from_mut(&args)?;
@@ -4294,7 +4295,7 @@ mod tests {
/// Creates vector of strings, Vec<String>
macro_rules! svec {
- ($($x:expr),* $(,)?) => (vec![$($x.to_string()),*]);
+ ($($x:expr),* $(,)?) => (vec![$($x.to_string().into()),*]);
}
#[test]
diff --git a/cli/lsp/testing/execution.rs b/cli/lsp/testing/execution.rs
index 6b89f0e43..e1189ec2c 100644
--- a/cli/lsp/testing/execution.rs
+++ b/cli/lsp/testing/execution.rs
@@ -212,7 +212,7 @@ impl TestRun {
) -> Result<(), AnyError> {
let args = self.get_args();
lsp_log!("Executing test run with arguments: {}", args.join(" "));
- let flags = flags_from_vec(args.into_iter().map(String::from).collect())?;
+ let flags = flags_from_vec(args.into_iter().map(From::from).collect())?;
let factory = CliFactory::from_flags(flags)?;
// Various test files should not share the same permissions in terms of
// `PermissionsContainer` - otherwise granting/revoking permissions in one
diff --git a/cli/main.rs b/cli/main.rs
index 729559d9a..32e40ff51 100644
--- a/cli/main.rs
+++ b/cli/main.rs
@@ -320,7 +320,7 @@ pub fn main() {
Box::new(util::draw_thread::DrawThread::show),
);
- let args: Vec<String> = env::args().collect();
+ let args: Vec<_> = env::args_os().collect();
// NOTE(lucacasonato): due to new PKU feature introduced in V8 11.6 we need to
// initialize the V8 platform on a parent thread of all threads that will spawn
diff --git a/cli/mainrt.rs b/cli/mainrt.rs
index ae4ea727f..56bde7c4b 100644
--- a/cli/mainrt.rs
+++ b/cli/mainrt.rs
@@ -68,10 +68,9 @@ fn unwrap_or_exit<T>(result: Result<T, AnyError>) -> T {
}
fn main() {
- let args: Vec<String> = env::args().collect();
+ let args: Vec<_> = env::args_os().collect();
let current_exe_path = current_exe().unwrap();
- let standalone =
- standalone::extract_standalone(&current_exe_path, args.clone());
+ let standalone = standalone::extract_standalone(&current_exe_path, args);
let future = async move {
match standalone {
Ok(Some(future)) => {
diff --git a/cli/standalone/binary.rs b/cli/standalone/binary.rs
index 2b334ec46..a3a12f5e2 100644
--- a/cli/standalone/binary.rs
+++ b/cli/standalone/binary.rs
@@ -2,6 +2,7 @@
use std::collections::BTreeMap;
use std::env::current_exe;
+use std::ffi::OsString;
use std::fs;
use std::future::Future;
use std::io::Read;
@@ -239,7 +240,7 @@ pub fn is_standalone_binary(exe_path: &Path) -> bool {
/// the bundle is executed. If not, this function exits with `Ok(None)`.
pub fn extract_standalone(
exe_path: &Path,
- cli_args: Vec<String>,
+ cli_args: Vec<OsString>,
) -> Result<
Option<impl Future<Output = Result<(Metadata, eszip::EszipV2), AnyError>>>,
AnyError,
@@ -281,7 +282,10 @@ pub fn extract_standalone(
.context("Failed to read metadata from the current executable")?;
let mut metadata: Metadata = serde_json::from_str(&metadata).unwrap();
- metadata.argv.append(&mut cli_args[1..].to_vec());
+ metadata.argv.reserve(cli_args.len() - 1);
+ for arg in cli_args.into_iter().skip(1) {
+ metadata.argv.push(arg.into_string().unwrap());
+ }
Ok((metadata, eszip))
}))