@@ -10,7 +10,6 @@ use crate::mem;
10
10
use crate :: num:: flt2dec;
11
11
use crate :: ops:: Deref ;
12
12
use crate :: result;
13
- use crate :: slice;
14
13
use crate :: str;
15
14
16
15
mod builders;
@@ -234,8 +233,6 @@ pub struct Formatter<'a> {
234
233
precision : Option < usize > ,
235
234
236
235
buf : & ' a mut ( dyn Write + ' a ) ,
237
- curarg : slice:: Iter < ' a , ArgumentV1 < ' a > > ,
238
- args : & ' a [ ArgumentV1 < ' a > ] ,
239
236
}
240
237
241
238
// NB. Argument is essentially an optimized partially applied formatting function,
@@ -1043,8 +1040,6 @@ pub fn write(output: &mut dyn Write, args: Arguments<'_>) -> Result {
1043
1040
buf : output,
1044
1041
align : rt:: v1:: Alignment :: Unknown ,
1045
1042
fill : ' ' ,
1046
- args : args. args ,
1047
- curarg : args. args . iter ( ) ,
1048
1043
} ;
1049
1044
1050
1045
let mut idx = 0 ;
@@ -1063,7 +1058,7 @@ pub fn write(output: &mut dyn Write, args: Arguments<'_>) -> Result {
1063
1058
// a string piece.
1064
1059
for ( arg, piece) in fmt. iter ( ) . zip ( args. pieces . iter ( ) ) {
1065
1060
formatter. buf . write_str ( * piece) ?;
1066
- formatter . run ( arg) ?;
1061
+ run ( & mut formatter , arg, & args . args ) ?;
1067
1062
idx += 1 ;
1068
1063
}
1069
1064
}
@@ -1077,6 +1072,39 @@ pub fn write(output: &mut dyn Write, args: Arguments<'_>) -> Result {
1077
1072
Ok ( ( ) )
1078
1073
}
1079
1074
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
+
1080
1108
/// Padding after the end of something. Returned by `Formatter::padding`.
1081
1109
#[ must_use = "don't forget to write the post padding" ]
1082
1110
struct PostPadding {
@@ -1114,41 +1142,6 @@ impl<'a> Formatter<'a> {
1114
1142
align : self . align ,
1115
1143
width : self . width ,
1116
1144
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 ( ) ,
1152
1145
}
1153
1146
}
1154
1147
0 commit comments