@@ -10,7 +10,6 @@ use crate::mem;
1010use crate :: num:: flt2dec;
1111use crate :: ops:: Deref ;
1212use crate :: result;
13- use crate :: slice;
1413use crate :: str;
1514
1615mod builders;
@@ -234,8 +233,6 @@ pub struct Formatter<'a> {
234233 precision : Option < usize > ,
235234
236235 buf : & ' a mut ( dyn Write + ' a ) ,
237- curarg : slice:: Iter < ' a , ArgumentV1 < ' a > > ,
238- args : & ' a [ ArgumentV1 < ' a > ] ,
239236}
240237
241238// NB. Argument is essentially an optimized partially applied formatting function,
@@ -1043,8 +1040,6 @@ pub fn write(output: &mut dyn Write, args: Arguments<'_>) -> Result {
10431040 buf : output,
10441041 align : rt:: v1:: Alignment :: Unknown ,
10451042 fill : ' ' ,
1046- args : args. args ,
1047- curarg : args. args . iter ( ) ,
10481043 } ;
10491044
10501045 let mut idx = 0 ;
@@ -1063,7 +1058,7 @@ pub fn write(output: &mut dyn Write, args: Arguments<'_>) -> Result {
10631058 // a string piece.
10641059 for ( arg, piece) in fmt. iter ( ) . zip ( args. pieces . iter ( ) ) {
10651060 formatter. buf . write_str ( * piece) ?;
1066- formatter . run ( arg) ?;
1061+ run ( & mut formatter , arg, & args . args ) ?;
10671062 idx += 1 ;
10681063 }
10691064 }
@@ -1077,6 +1072,39 @@ pub fn write(output: &mut dyn Write, args: Arguments<'_>) -> Result {
10771072 Ok ( ( ) )
10781073}
10791074
1075+ fn run ( fmt : & mut Formatter < ' _ > , arg : & rt:: v1:: Argument , args : & [ ArgumentV1 < ' _ > ] ) -> Result {
1076+ fmt. fill = arg. format . fill ;
1077+ fmt. align = arg. format . align ;
1078+ fmt. flags = arg. format . flags ;
1079+ fmt. width = getcount ( args, & arg. format . width ) ;
1080+ fmt. precision = getcount ( args, & arg. format . precision ) ;
1081+
1082+ // Extract the correct argument
1083+ let value = {
1084+ #[ cfg( bootstrap) ]
1085+ {
1086+ match arg. position {
1087+ rt:: v1:: Position :: At ( i) => args[ i] ,
1088+ }
1089+ }
1090+ #[ cfg( not( bootstrap) ) ]
1091+ {
1092+ args[ arg. position ]
1093+ }
1094+ } ;
1095+
1096+ // Then actually do some printing
1097+ ( value. formatter ) ( value. value , fmt)
1098+ }
1099+
1100+ fn getcount ( args : & [ ArgumentV1 < ' _ > ] , cnt : & rt:: v1:: Count ) -> Option < usize > {
1101+ match * cnt {
1102+ rt:: v1:: Count :: Is ( n) => Some ( n) ,
1103+ rt:: v1:: Count :: Implied => None ,
1104+ rt:: v1:: Count :: Param ( i) => args[ i] . as_usize ( ) ,
1105+ }
1106+ }
1107+
10801108/// Padding after the end of something. Returned by `Formatter::padding`.
10811109#[ must_use = "don't forget to write the post padding" ]
10821110struct PostPadding {
@@ -1114,41 +1142,6 @@ impl<'a> Formatter<'a> {
11141142 align : self . align ,
11151143 width : self . width ,
11161144 precision : self . precision ,
1117-
1118- // These only exist in the struct for the `run` method,
1119- // which won’t be used together with this method.
1120- curarg : self . curarg . clone ( ) ,
1121- args : self . args ,
1122- }
1123- }
1124-
1125- // First up is the collection of functions used to execute a format string
1126- // at runtime. This consumes all of the compile-time statics generated by
1127- // the format! syntax extension.
1128- fn run ( & mut self , arg : & rt:: v1:: Argument ) -> Result {
1129- // Fill in the format parameters into the formatter
1130- self . fill = arg. format . fill ;
1131- self . align = arg. format . align ;
1132- self . flags = arg. format . flags ;
1133- self . width = self . getcount ( & arg. format . width ) ;
1134- self . precision = self . getcount ( & arg. format . precision ) ;
1135-
1136- // Extract the correct argument
1137- let value = match arg. position {
1138- rt:: v1:: Position :: Next => * self . curarg . next ( ) . unwrap ( ) ,
1139- rt:: v1:: Position :: At ( i) => self . args [ i] ,
1140- } ;
1141-
1142- // Then actually do some printing
1143- ( value. formatter ) ( value. value , self )
1144- }
1145-
1146- fn getcount ( & mut self , cnt : & rt:: v1:: Count ) -> Option < usize > {
1147- match * cnt {
1148- rt:: v1:: Count :: Is ( n) => Some ( n) ,
1149- rt:: v1:: Count :: Implied => None ,
1150- rt:: v1:: Count :: Param ( i) => self . args [ i] . as_usize ( ) ,
1151- rt:: v1:: Count :: NextParam => self . curarg . next ( ) ?. as_usize ( ) ,
11521145 }
11531146 }
11541147
0 commit comments