0
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-03-03 09:31:22 -05:00

perf(cli): use args_os (#23039)

Extracted from #22718
This commit is contained in:
Matt Mastracci 2024-03-22 14:03:56 -07:00 committed by GitHub
parent 08ec6e5831
commit 86cdf37033
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 13 additions and 9 deletions

View file

@ -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]

View file

@ -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

View file

@ -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

View file

@ -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)) => {

View file

@ -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))
}))