@@ -207,7 +207,8 @@ pub fn emit(cli: &Cli) -> TokenStream { |
207 | 207 | // would sit in the layer that outranks every other, named after a flag nobody |
208 | 208 | // typed — and counted twice by a `union` setting whose CLI also has an |
209 | 209 | // `EnvLayer`. The environment has a layer of its own to arrive in. |
210 | | - let mut partial = read_argv(Self::command(), argv)?; |
| 210 | + #defaults |
| 211 | + read_argv_into(Self::command(), argv, &mut partial)?; |
211 | 212 | let __usage_settings = settings_layer(&partial); |
212 | 213 | check(&mut partial)?; |
213 | 214 | let __usage_built = Self { |
@@ -336,7 +337,24 @@ pub fn emit(cli: &Cli) -> TokenStream { |
336 | 337 | argv: &'v [&'v ::std::ffi::OsStr], |
337 | 338 | ) -> ::std::result::Result<Partial, usage_argv::Error<'static, 'v>> { |
338 | 339 | #defaults |
| 340 | + read_argv_into(command, argv, &mut partial)?; |
| 341 | + ::std::result::Result::Ok(partial) |
| 342 | + } |
339 | 343 |
|
| 344 | + /// `read_argv`, filling a partial the caller already owns. |
| 345 | + /// |
| 346 | + /// The entry points call this rather than `read_argv`, because a `Partial` is |
| 347 | + /// the whole CLI's worth of accumulator — every command's fields, inlined — |
| 348 | + /// and returning one by value is a memcpy of all of it. At mise's scale that is |
| 349 | + /// 11KB a move, and returning it up the chain from here to `parse_from` made |
| 350 | + /// four: 87% of a parse was spent copying a struct of which all but one |
| 351 | + /// command's worth goes untouched. Threading `&mut` puts the partial in the |
| 352 | + /// frame that will consume it, leaving only the one copy that builds it. |
| 353 | + pub fn read_argv_into<'v>( |
| 354 | + command: &'static usage_argv::Command<'static>, |
| 355 | + argv: &'v [&'v ::std::ffi::OsStr], |
| 356 | + partial: &mut Partial, |
| 357 | + ) -> ::std::result::Result<(), usage_argv::Error<'static, 'v>> { |
340 | 358 | let mut __usage_parser = usage_argv::Parser::new(command, argv); |
341 | 359 | while let ::std::option::Option::Some(__usage_event) = |
342 | 360 | __usage_parser.next_event() |
@@ -365,10 +383,10 @@ pub fn emit(cli: &Cli) -> TokenStream { |
365 | 383 | // `apply` handles this command's own fields and routes anything |
366 | 384 | // else into its subcommands, which is why a nested command needs |
367 | 385 | // nothing extra here. |
368 | | - apply(&mut partial, &__usage_event); |
| 386 | + apply(partial, &__usage_event); |
369 | 387 | } |
370 | 388 |
|
371 | | - ::std::result::Result::Ok(partial) |
| 389 | + ::std::result::Result::Ok(()) |
372 | 390 | } |
373 | 391 |
|
374 | 392 | /// Every token read, and everything decided after the last one. |
@@ -381,11 +399,22 @@ pub fn emit(cli: &Cli) -> TokenStream { |
381 | 399 | command: &'static usage_argv::Command<'static>, |
382 | 400 | argv: &'v [&'v ::std::ffi::OsStr], |
383 | 401 | ) -> ::std::result::Result<Partial, usage_argv::Error<'static, 'v>> { |
384 | | - let mut partial = read_argv(command, argv)?; |
385 | | - check(&mut partial)?; |
| 402 | + #defaults |
| 403 | + read_into(command, argv, &mut partial)?; |
386 | 404 | ::std::result::Result::Ok(partial) |
387 | 405 | } |
388 | 406 |
|
| 407 | + /// `read`, filling a partial the caller already owns. See `read_argv_into`. |
| 408 | + pub fn read_into<'v>( |
| 409 | + command: &'static usage_argv::Command<'static>, |
| 410 | + argv: &'v [&'v ::std::ffi::OsStr], |
| 411 | + partial: &mut Partial, |
| 412 | + ) -> ::std::result::Result<(), usage_argv::Error<'static, 'v>> { |
| 413 | + read_argv_into(command, argv, partial)?; |
| 414 | + check(partial)?; |
| 415 | + ::std::result::Result::Ok(()) |
| 416 | + } |
| 417 | + |
389 | 418 | #settings_given |
390 | 419 | #settings_bindings |
391 | 420 | #settings_layer |
@@ -430,7 +459,10 @@ pub fn emit(cli: &Cli) -> TokenStream { |
430 | 459 | pub fn parse_from<'v>( |
431 | 460 | argv: &'v [&'v ::std::ffi::OsStr], |
432 | 461 | ) -> ::std::result::Result<Self, usage_argv::Error<'static, 'v>> { |
433 | | - let partial = read(Self::command(), argv)?; |
| 462 | + // The partial is built here and filled through `&mut`, rather than |
| 463 | + // returned up the chain: see `read_argv_into`. |
| 464 | + #defaults |
| 465 | + read_into(Self::command(), argv, &mut partial)?; |
434 | 466 | ::std::result::Result::Ok(Self { |
435 | 467 | #sub_build |
436 | 468 | #(#field_finals),* |
|