@@ -1153,46 +1153,55 @@ impl<'a> Formatter<'a> {
1153
1153
sign = Some ( '+' ) ; width += 1 ;
1154
1154
}
1155
1155
1156
- let prefixed = self . alternate ( ) ;
1157
- if prefixed {
1156
+ let prefix = if self . alternate ( ) {
1158
1157
width += prefix. chars ( ) . count ( ) ;
1159
- }
1158
+ Some ( prefix)
1159
+ } else {
1160
+ None
1161
+ } ;
1160
1162
1161
1163
// Writes the sign if it exists, and then the prefix if it was requested
1162
- let write_prefix = |f : & mut Formatter | {
1164
+ #[ inline( never) ]
1165
+ fn write_prefix ( f : & mut Formatter , sign : Option < char > , prefix : Option < & str > ) -> Result {
1163
1166
if let Some ( c) = sign {
1164
1167
f. buf . write_char ( c) ?;
1165
1168
}
1166
- if prefixed { f. buf . write_str ( prefix) }
1167
- else { Ok ( ( ) ) }
1168
- } ;
1169
+ if let Some ( prefix) = prefix {
1170
+ f. buf . write_str ( prefix)
1171
+ } else {
1172
+ Ok ( ( ) )
1173
+ }
1174
+ }
1169
1175
1170
1176
// The `width` field is more of a `min-width` parameter at this point.
1171
1177
match self . width {
1172
1178
// If there's no minimum length requirements then we can just
1173
1179
// write the bytes.
1174
1180
None => {
1175
- write_prefix ( self ) ?; self . buf . write_str ( buf)
1181
+ write_prefix ( self , sign, prefix) ?;
1182
+ self . buf . write_str ( buf)
1176
1183
}
1177
1184
// Check if we're over the minimum width, if so then we can also
1178
1185
// just write the bytes.
1179
1186
Some ( min) if width >= min => {
1180
- write_prefix ( self ) ?; self . buf . write_str ( buf)
1187
+ write_prefix ( self , sign, prefix) ?;
1188
+ self . buf . write_str ( buf)
1181
1189
}
1182
1190
// The sign and prefix goes before the padding if the fill character
1183
1191
// is zero
1184
1192
Some ( min) if self . sign_aware_zero_pad ( ) => {
1185
1193
self . fill = '0' ;
1186
1194
self . align = rt:: v1:: Alignment :: Right ;
1187
- write_prefix ( self ) ?;
1195
+ write_prefix ( self , sign , prefix ) ?;
1188
1196
self . with_padding ( min - width, rt:: v1:: Alignment :: Right , |f| {
1189
1197
f. buf . write_str ( buf)
1190
1198
} )
1191
1199
}
1192
1200
// Otherwise, the sign and prefix goes after the padding
1193
1201
Some ( min) => {
1194
1202
self . with_padding ( min - width, rt:: v1:: Alignment :: Right , |f| {
1195
- write_prefix ( f) ?; f. buf . write_str ( buf)
1203
+ write_prefix ( f, sign, prefix) ?;
1204
+ f. buf . write_str ( buf)
1196
1205
} )
1197
1206
}
1198
1207
}
0 commit comments