@@ -255,12 +255,12 @@ macro_rules! impl_Display {
255255
256256 let quad = remain % 100_00 ;
257257 remain /= 100_00 ;
258- let p1 = ( quad / 100 ) as usize * 2 ;
259- let p2 = ( quad % 100 ) as usize * 2 ;
260- buf[ offset + 0 ] . write( DEC_DIGITS_LUT [ p1 + 0 ] ) ;
261- buf[ offset + 1 ] . write( DEC_DIGITS_LUT [ p1 + 1 ] ) ;
262- buf[ offset + 2 ] . write( DEC_DIGITS_LUT [ p2 + 0 ] ) ;
263- buf[ offset + 3 ] . write( DEC_DIGITS_LUT [ p2 + 1 ] ) ;
258+ let i1 = ( quad / 100 ) as usize ;
259+ let i2 = ( quad % 100 ) as usize ;
260+ buf[ offset + 0 ] . write( DEC_DIGITS_LUT [ i1 * 2 + 0 ] ) ;
261+ buf[ offset + 1 ] . write( DEC_DIGITS_LUT [ i1 * 2 + 1 ] ) ;
262+ buf[ offset + 2 ] . write( DEC_DIGITS_LUT [ i2 * 2 + 0 ] ) ;
263+ buf[ offset + 3 ] . write( DEC_DIGITS_LUT [ i2 * 2 + 1 ] ) ;
264264 }
265265
266266 // Format per two digits from the lookup table.
@@ -270,24 +270,24 @@ macro_rules! impl_Display {
270270 unsafe { core:: hint:: assert_unchecked( offset <= buf. len( ) ) }
271271 offset -= 2 ;
272272
273- let p = ( remain % 100 ) as usize * 2 ;
273+ let i = ( remain % 100 ) as usize ;
274274 remain /= 100 ;
275- buf[ offset + 0 ] . write( DEC_DIGITS_LUT [ p + 0 ] ) ;
276- buf[ offset + 1 ] . write( DEC_DIGITS_LUT [ p + 1 ] ) ;
275+ buf[ offset + 0 ] . write( DEC_DIGITS_LUT [ i * 2 + 0 ] ) ;
276+ buf[ offset + 1 ] . write( DEC_DIGITS_LUT [ i * 2 + 1 ] ) ;
277277 }
278278
279279 // Format the last remaining digit, if any.
280- if offset != 0 && remain != 0 || offset == MAX_DEC_N {
280+ if offset != 0 && remain != 0 || self == 0 {
281281 // SAFETY: Offset from the initial buf.len() gets deducted
282282 // with underflow checks exclusively.
283283 unsafe { core:: hint:: assert_unchecked( offset <= buf. len( ) ) }
284284 offset -= 1 ;
285285
286286 // Either the compiler sees that remain < 10, or it prevents
287287 // a boundary check up next.
288- let p = ( remain % 10 ) as usize * 2 ;
288+ let i = ( remain & 15 ) as usize ;
289289 // not used: remain = 0;
290- buf[ offset] . write( DEC_DIGITS_LUT [ p + 1 ] ) ;
290+ buf[ offset] . write( DEC_DIGITS_LUT [ i * 2 + 1 ] ) ;
291291 }
292292
293293 // SAFETY: All buf content since offset is set with bytes form
0 commit comments