Skip to content

Commit

Permalink
Apply review
Browse files Browse the repository at this point in the history
  • Loading branch information
HalidOdat committed Sep 16, 2023
1 parent 16ca73c commit ccbc568
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 31 deletions.
3 changes: 0 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ rust-version = "1.36"
# one case, and only f64) at the cost of some performance.
small = []

# Enable to `Number.prototype.toFixed()` float to string conversion.
to-fixed = []

[dependencies]
no-panic = { version = "0.1", optional = true }

Expand Down
20 changes: 1 addition & 19 deletions src/buffer/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#[cfg(feature = "to-fixed")]
use crate::pretty::to_fixed::MAX_BUFFER_SIZE;

use crate::raw;
Expand All @@ -11,10 +10,6 @@ const NAN: &str = "NaN";
const INFINITY: &str = "Infinity";
const NEG_INFINITY: &str = "-Infinity";

#[cfg(not(feature = "to-fixed"))]
const BUFFER_SIZE: usize = 25;

#[cfg(feature = "to-fixed")]
const BUFFER_SIZE: usize = MAX_BUFFER_SIZE;

/// Safe API for formatting floating point numbers to text.
Expand All @@ -26,6 +21,7 @@ const BUFFER_SIZE: usize = MAX_BUFFER_SIZE;
/// let printed = buffer.format_finite(1.234);
/// assert_eq!(printed, "1.234");
/// ```
#[derive(Copy, Clone)]
pub struct Buffer {
bytes: [MaybeUninit<u8>; BUFFER_SIZE],
}
Expand Down Expand Up @@ -104,7 +100,6 @@ impl Buffer {
/// [spec]: https://tc39.es/ecma262/#sec-numeric-types-number-tofixed
#[cfg_attr(feature = "no-panic", inline)]
#[cfg_attr(feature = "no-panic", no_panic)]
#[cfg(feature = "to-fixed")]
pub fn format_to_fixed<F: FloatToFixed>(&mut self, f: F, fraction_digits: u8) -> &str {
let fraction_digits = fraction_digits.min(100);

Expand All @@ -122,15 +117,6 @@ impl Buffer {
}
}

impl Copy for Buffer {}

impl Clone for Buffer {
#[inline]
fn clone(&self) -> Self {
Buffer::new()
}
}

impl Default for Buffer {
#[inline]
#[cfg_attr(feature = "no-panic", no_panic)]
Expand Down Expand Up @@ -163,8 +149,6 @@ pub trait Sealed: Copy {
fn is_nonfinite(self) -> bool;
fn format_nonfinite(self) -> &'static str;
unsafe fn write_to_ryu_buffer(self, result: *mut u8) -> usize;

#[cfg(feature = "to-fixed")]
unsafe fn write_to_ryu_buffer_to_fixed(self, fraction_digits: u8, result: *mut u8) -> usize;
}

Expand Down Expand Up @@ -197,7 +181,6 @@ impl Sealed for f32 {
}

#[inline]
#[cfg(feature = "to-fixed")]
unsafe fn write_to_ryu_buffer_to_fixed(self, _fraction_digits: u8, _result: *mut u8) -> usize {
panic!("toFixed for f32 type is not implemented yet!")
}
Expand Down Expand Up @@ -232,7 +215,6 @@ impl Sealed for f64 {
}

#[inline]
#[cfg(feature = "to-fixed")]
unsafe fn write_to_ryu_buffer_to_fixed(self, fraction_digits: u8, result: *mut u8) -> usize {
raw::format64_to_fixed(self, fraction_digits, result)
}
Expand Down
4 changes: 1 addition & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,6 @@ pub use crate::buffer::{Buffer, Float, FloatToFixed};

/// Unsafe functions that mirror the API of the C implementation of Ryū.
pub mod raw {
pub use crate::pretty::{format32, format64};

#[cfg(feature = "to-fixed")]
pub use crate::pretty::format64_to_fixed;
pub use crate::pretty::{format32, format64};
}
3 changes: 0 additions & 3 deletions src/pretty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ use core::ptr;
#[cfg(feature = "no-panic")]
use no_panic::no_panic;

#[cfg(feature = "to-fixed")]
pub mod to_fixed;

#[cfg(feature = "to-fixed")]
pub use to_fixed::{format64_to_fixed, Cursor};

/// Print f64 to the given buffer and return number of bytes written.
Expand Down
5 changes: 2 additions & 3 deletions src/pretty/to_fixed/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ impl Cursor {

let result = self.buffer.offset(self.index);

for i in (0u32..5).step_by(4) {
for i in [0, 4] {
let c = digits % 10000;
digits /= 10000;
let c0 = (c % 100) << 1;
Expand Down Expand Up @@ -231,8 +231,7 @@ impl Cursor {
}
}

/// This assertion should not fail, because of the abs(f) >= 1e21 check
/// that falls back to ToString ([`format64`]).
/// Because of the abs(f) >= 1e21 check, falls back to ToString ([`format64`]).
///
/// See tests.
const MAX_EXPONENT: u32 = 0b100_0100_0100; // 1029
Expand Down

0 comments on commit ccbc568

Please sign in to comment.