Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #115129 - m-ou-se:fmt-args-new-repr, r=<try>
New fmt::Arguments representation. This changes the internal representation of `fmt::Arguments` to reduce it in size and make it possible to convert a `&'static str` to a `fmt::Arguments` without additional indirection. Part of #99012 fmt::Arguments stores three slices: 1. The slice of string literals between the placeholders. 2. The details of the placeholders (format options, which argument to display there, etc.). 3. The arguments. 2 is omitted when it's just all arguments once in order without additional options. Before this change, fmt::Arguments stores each of these as a &[] (or Option of that), resulting in a total size of six words/pointers. However, we don't need to store the length of each of these slices separately, as we may (unsafely) assume that the indexes of the fmt::Arguments generated by format_args!() are never out of bounds, and the number of placeholders and number of strings between them must be nearly equal. This PR changes the struct to store three pointers without length, and a single 'number of parts' counter that is the sum of the number of placeholders and string pieces. Additionally, this PR adds a special case for 1 part (that is, one string piece and no placeholders) to store the string pointer directly instead of through a slice of length 1. This makes it possible for `fmt::Arguments::new_str(&'static str)` to exist, which unlike before (`new_const(&[&'static str])`) doesn't need to borrow anything other than the string itself.
- Loading branch information