aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/long_mode/display.rs60
1 files changed, 44 insertions, 16 deletions
diff --git a/src/long_mode/display.rs b/src/long_mode/display.rs
index da138bb..198a930 100644
--- a/src/long_mode/display.rs
+++ b/src/long_mode/display.rs
@@ -758,11 +758,15 @@ impl DisplaySink for alloc::string::String {
fn write_u8(&mut self, mut v: u8) -> Result<(), core::fmt::Error> {
// we can fairly easily predict the size of a formatted string here with lzcnt, which also
// means we can write directly into the correct offsets of the output string.
- let printed_size = (((8 - v.leading_zeros()) >> 2) + 1) as usize;
+ let mut printed_size = ((8 - v.leading_zeros() + 3) >> 2) as usize;
+ if printed_size == 0 {
+ printed_size = 1;
+ }
+
self.reserve(printed_size);
let buf = unsafe { self.as_mut_vec() };
- let p = buf.as_mut_ptr();
+ let p = unsafe { buf.as_mut_ptr().offset(buf.len() as isize) };
let mut curr = printed_size;
loop {
let digit = v % 16;
@@ -791,11 +795,15 @@ impl DisplaySink for alloc::string::String {
fn write_u16(&mut self, mut v: u16) -> Result<(), core::fmt::Error> {
// we can fairly easily predict the size of a formatted string here with lzcnt, which also
// means we can write directly into the correct offsets of the output string.
- let printed_size = (((16 - v.leading_zeros()) >> 2) + 1) as usize;
+ let mut printed_size = ((16 - v.leading_zeros() + 3) >> 2) as usize;
+ if printed_size == 0 {
+ printed_size = 1;
+ }
+
self.reserve(printed_size);
let buf = unsafe { self.as_mut_vec() };
- let p = buf.as_mut_ptr();
+ let p = unsafe { buf.as_mut_ptr().offset(buf.len() as isize) };
let mut curr = printed_size;
loop {
let digit = v % 16;
@@ -826,11 +834,15 @@ impl DisplaySink for alloc::string::String {
fn write_u32(&mut self, mut v: u32) -> Result<(), core::fmt::Error> {
// we can fairly easily predict the size of a formatted string here with lzcnt, which also
// means we can write directly into the correct offsets of the output string.
- let printed_size = (((32 - v.leading_zeros()) >> 2) + 1) as usize;
+ let mut printed_size = ((32 - v.leading_zeros() + 3) >> 2) as usize;
+ if printed_size == 0 {
+ printed_size = 1;
+ }
+
self.reserve(printed_size);
let buf = unsafe { self.as_mut_vec() };
- let p = buf.as_mut_ptr();
+ let p = unsafe { buf.as_mut_ptr().offset(buf.len() as isize) };
let mut curr = printed_size;
loop {
let digit = v % 16;
@@ -860,11 +872,15 @@ impl DisplaySink for alloc::string::String {
fn write_u64(&mut self, mut v: u64) -> Result<(), core::fmt::Error> {
// we can fairly easily predict the size of a formatted string here with lzcnt, which also
// means we can write directly into the correct offsets of the output string.
- let printed_size = (((64 - v.leading_zeros()) >> 2) + 1) as usize;
+ let mut printed_size = ((64 - v.leading_zeros() + 3) >> 2) as usize;
+ if printed_size == 0 {
+ printed_size = 1;
+ }
+
self.reserve(printed_size);
let buf = unsafe { self.as_mut_vec() };
- let p = buf.as_mut_ptr();
+ let p = unsafe { buf.as_mut_ptr().offset(buf.len() as isize) };
let mut curr = printed_size;
loop {
let digit = v % 16;
@@ -1140,10 +1156,13 @@ impl DisplaySink for BigEnoughString {
fn write_u8(&mut self, mut v: u8) -> Result<(), core::fmt::Error> {
// we can fairly easily predict the size of a formatted string here with lzcnt, which also
// means we can write directly into the correct offsets of the output string.
- let printed_size = (((8 - v.leading_zeros()) >> 2) + 1) as usize;
+ let mut printed_size = ((8 - v.leading_zeros() + 3) >> 2) as usize;
+ if printed_size == 0 {
+ printed_size = 1;
+ }
let buf = unsafe { self.content.as_mut_vec() };
- let p = buf.as_mut_ptr();
+ let p = unsafe { buf.as_mut_ptr().offset(buf.len() as isize) };
let mut curr = printed_size;
loop {
let digit = v % 16;
@@ -1172,10 +1191,13 @@ impl DisplaySink for BigEnoughString {
fn write_u16(&mut self, mut v: u16) -> Result<(), core::fmt::Error> {
// we can fairly easily predict the size of a formatted string here with lzcnt, which also
// means we can write directly into the correct offsets of the output string.
- let printed_size = (((16 - v.leading_zeros()) >> 2) + 1) as usize;
+ let mut printed_size = ((16 - v.leading_zeros() + 3) >> 2) as usize;
+ if printed_size == 0 {
+ printed_size = 1;
+ }
let buf = unsafe { self.content.as_mut_vec() };
- let p = buf.as_mut_ptr();
+ let p = unsafe { buf.as_mut_ptr().offset(buf.len() as isize) };
let mut curr = printed_size;
loop {
let digit = v % 16;
@@ -1205,10 +1227,13 @@ impl DisplaySink for BigEnoughString {
fn write_u32(&mut self, mut v: u32) -> Result<(), core::fmt::Error> {
// we can fairly easily predict the size of a formatted string here with lzcnt, which also
// means we can write directly into the correct offsets of the output string.
- let printed_size = (((32 - v.leading_zeros()) >> 2) + 1) as usize;
+ let mut printed_size = ((32 - v.leading_zeros() + 3) >> 2) as usize;
+ if printed_size == 0 {
+ printed_size = 1;
+ }
let buf = unsafe { self.content.as_mut_vec() };
- let p = buf.as_mut_ptr();
+ let p = unsafe { buf.as_mut_ptr().offset(buf.len() as isize) };
let mut curr = printed_size;
loop {
let digit = v % 16;
@@ -1238,10 +1263,13 @@ impl DisplaySink for BigEnoughString {
fn write_u64(&mut self, mut v: u64) -> Result<(), core::fmt::Error> {
// we can fairly easily predict the size of a formatted string here with lzcnt, which also
// means we can write directly into the correct offsets of the output string.
- let printed_size = (((64 - v.leading_zeros()) >> 2) + 1) as usize;
+ let mut printed_size = ((64 - v.leading_zeros() + 3) >> 2) as usize;
+ if printed_size == 0 {
+ printed_size = 1;
+ }
let buf = unsafe { self.content.as_mut_vec() };
- let p = buf.as_mut_ptr();
+ let p = unsafe { buf.as_mut_ptr().offset(buf.len() as isize) };
let mut curr = printed_size;
loop {
let digit = v % 16;