Std.Args.Spec
1 declaration
type
SpecThis declaration introduces a public type.
What it does
What a program accepts, and the index that makes reading it one lookup.
Reading arguments by scanning for each one in turn — which is what asking
"was --verbose given?" separately from "what is --out?" amounts to —
walks the whole command line once per question. Ten options is ten passes,
and each pass compares every argument against a name.
So the names are indexed once, when the spec is built, and the command line
is then read in a single pass: every argument is one lookup rather than a
search. What that costs is one map per spec, built at startup; what it buys
is that adding an option to a program does not make reading its arguments
slower.
The difference is the shape of the growth rather than a constant. Reading
every option of a command line that gives all of them, measured at 25, 50,
100 and 200 options: scanning takes 9ms, 34ms, 134ms and 530ms — four times
the work for twice the options — while one pass and a lookup each takes
6ms, 11ms, 22ms and 43ms, which is twice for twice. A tool with a handful
of options would not notice either; the point is that one of them stops
being usable as the tool grows and the other does not.
byLong and byShort hold positions into opts rather than the options
themselves, so an option is stored once however many ways it can be
written.
Read the signature
- This declaration has no value signature because it introduces a type or trait.
