Remove lookup table

This commit is contained in:
novacrazy
2024-08-25 21:58:18 -05:00
parent ce1d1a5261
commit 79bdcd5c4d
3 changed files with 9 additions and 48 deletions
+5 -4
View File
@@ -28,8 +28,7 @@ rand = ["dep:rand", "time/rand"]
quickcheck = ["dep:quickcheck", "time/quickcheck"]
schema = ["schemars"]
verify = [] # Verify numeric input during parsing
lookup = [] # Use lookup table during formatting
default = ["std", "serde", "lookup"]
default = ["std", "serde", "rkyv_08"]
[dependencies]
serde = { optional = true, version = "1" }
@@ -45,10 +44,12 @@ quickcheck = { optional = true, version = "1.0", default-features = false }
worker = { optional = true, version = "0.3.0" }
js-sys = { optional = true, version = "0.3" }
ramhorns = { optional = true, version = "1.0" }
rkyv_08 = { package = "rkyv", optional = true, version = "0.8.0-alpha.3", default-features = false, features = ["bytecheck"] }
fred = { optional = true, version = "9.0", default-features = false }
rkyv_07 = { package = "rkyv", optional = true, version = "0.7", default-features = false, features = ["validation"] }
rend = { optional = true, version = "0.4", default-features = false }
fred = { optional = true, version = "9.0", default-features = false }
rkyv_08 = { package = "rkyv", optional = true, version = "0.8.0-alpha.3", default-features = false, features = ["bytecheck"] }
[dev-dependencies]
time = { version = "0.3", features = ["macros", "parsing", "formatting"] }
-6
View File
@@ -40,9 +40,6 @@ Similarly, when deserializing, it supports either an ISO8601 string or an `i64`
* `std` (default)
- Enables standard library features, such as getting the current time.
* `lookup` (default)
- Enables use of a 200-byte lookup table during formatting. Slightly faster with a hot cache. Disabling saves 200 bytes at a ~20% slowdown.
* `serde` (default)
- Enables serde implementations for `Timestamp` and [`TimestampStr`]
@@ -57,9 +54,6 @@ Similarly, when deserializing, it supports either an ISO8601 string or an `i64`
- Verifies numeric inputs when parsing and fails when non-numeric input is found.
- When disabled, parsing ignores invalid input, possibly giving garbage timestamps.
* `nightly`
- Enables nightly-specific optimizations, but without it will fallback to workarounds to enable the same optimizations.
* `pg`
- Enables `ToSql`/`FromSql` implementations for `Timestamp` so it can be directly stored/fetched from a PostgreSQL database using `rust-postgres`
+4 -38
View File
@@ -3,20 +3,6 @@ use time::{PrimitiveDateTime, UtcOffset};
use crate::ts_str::{template, FormatString, IsValidFormat, TimestampStr};
#[cfg(all(feature = "lookup", not(target_arch = "wasm32")))]
static LOOKUP: [[u8; 2]; 100] = {
let mut table = [[0; 2]; 100];
let mut i: u8 = 0;
while i < 100 {
let (a, b) = (i / 10, i % 10);
table[i as usize] = [a + b'0', b + b'0'];
i += 1;
}
table
};
#[rustfmt::skip]
#[allow(unused_assignments, clippy::identity_op)]
#[inline(always)]
@@ -24,16 +10,6 @@ pub fn do_format<F: t::Bit, O: t::Bit, P: t::Unsigned>(ts: PrimitiveDateTime, of
where
FormatString<F, O, P>: IsValidFormat,
{
// Prefetch the table while datetime parts are being destructured.
// Might cause slightly worse microbenchmark performance,
// but may save a couple nanoseconds in real applications.
#[cfg(all(feature = "lookup", any(target_arch = "x86_64", target_arch = "x86")))]
// SAFETY: prefetching has no significant side effects nor safety concerns
unsafe {
import_intrinsics!(x86::{_mm_prefetch, _MM_HINT_T0});
_mm_prefetch::<_MM_HINT_T0>(LOOKUP.as_ptr().cast());
}
// decompose timestamp
let (mut year, month, day) = crate::impls::to_calendar_date(ts.date());
let (hour, minute, second, nanoseconds) = ts.as_hms_nano();
@@ -67,24 +43,14 @@ where
// combine these so the compiler can optimize both operations
(value, d1) = (value / 100, value % 100);
#[cfg(all(feature = "lookup", not(target_arch = "wasm32")))]
{
let e = LOOKUP[d1 as usize];
len -= 1; buf[len] = e[1];
len -= 1; buf[len] = e[0];
}
#[cfg(not(all(feature = "lookup", not(target_arch = "wasm32"))))]
{
let (a, b) = (d1 / 10, d1 % 10);
len -= 1; buf[len] = (b as u8) | b'0';
len -= 1; buf[len] = (a as u8) | b'0';
}
let (a, b) = (d1 / 10, d1 % 10);
len -= 1; buf[len] = (b as u8) | b'0';
len -= 1; buf[len] = (a as u8) | b'0';
}
// handle remainder
if len == 1 {
buf[0] = (value as u8) + b'0';
buf[0] = (value as u8) | b'0';
}
}};
}