Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,11 @@ macro_rules! impl_Integer {
self.unsigned_abs(),
(&mut buf[offset..]).try_into().unwrap(),
);
if self < 0 {
offset -= 1;
buf[offset].write(b'-');
}
// Always write the sign and drop it for non-negative values. A
// branch here mispredicts on input with mixed signs.
// SAFETY: The magnitude has at most MAX_STR_LEN - 1 digits.
unsafe { buf.get_unchecked_mut(offset - 1).write(b'-') };
offset -= (self < 0) as usize;
// SAFETY: Starting from `offset`, all elements of the slice have been set.
unsafe { slice_buffer_to_str(buf, offset) }
}
Expand Down
2 changes: 2 additions & 0 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ test! {
test_u64_half(u64::from(u32::MAX), "4294967295")
test_u64_max(u64::MAX, "18446744073709551615")
test_i64_min(i64::MIN, "-9223372036854775808")
test_i64_max(i64::MAX, "9223372036854775807")
test_i32_neg_1(-1i32, "-1")

test_i16_0(0i16, "0")
test_i16_min(i16::MIN, "-32768")
Expand Down
Loading