@@ -8,7 +8,7 @@ use value_trait::StaticNode;
8
8
#[ cfg_attr( not( feature = "no-inline" ) , inline( always) ) ]
9
9
#[ allow( clippy:: cast_ptr_alignment) ]
10
10
pub fn is_valid_true_atom ( loc : & [ u8 ] ) -> bool {
11
- debug_assert ! ( loc. len( ) >= 8 , "input too short to safely read a u64 from " ) ;
11
+ debug_assert ! ( loc. len( ) >= 8 , "loc too short for a u64 read " ) ;
12
12
13
13
// TODO is this expensive?
14
14
let mut error: u64 ;
@@ -20,7 +20,7 @@ pub fn is_valid_true_atom(loc: &[u8]) -> bool {
20
20
21
21
// TODO: does this has the same effect as:
22
22
// std::memcpy(&locval, loc, sizeof(uint64_t));
23
- let locval: u64 = * ( loc. as_ptr ( ) . cast :: < u64 > ( ) ) ;
23
+ let locval: u64 = loc. as_ptr ( ) . cast :: < u64 > ( ) . read_unaligned ( ) ;
24
24
25
25
error = ( locval & MASK4 ) ^ TV ;
26
26
error |= u64:: from ( is_not_structural_or_whitespace ( * loc. get_kinda_unchecked ( 4 ) ) ) ;
@@ -45,6 +45,8 @@ macro_rules! get {
45
45
#[ cfg_attr( not( feature = "no-inline" ) , inline( always) ) ]
46
46
#[ allow( clippy:: cast_ptr_alignment, unused_unsafe) ]
47
47
pub fn is_valid_false_atom ( loc : & [ u8 ] ) -> bool {
48
+ debug_assert ! ( loc. len( ) >= 8 , "loc too short for a u64 read" ) ;
49
+
48
50
// TODO: this is ugly and probably copies data every time
49
51
let mut error: u64 ;
50
52
unsafe {
@@ -54,7 +56,7 @@ pub fn is_valid_false_atom(loc: &[u8]) -> bool {
54
56
const FV : u64 = 0x00_00_00_65_73_6c_61_66 ;
55
57
const MASK5 : u64 = 0x00_00_00_ff_ff_ff_ff_ff ;
56
58
57
- let locval: u64 = * ( loc. as_ptr ( ) . cast :: < u64 > ( ) ) ;
59
+ let locval: u64 = loc. as_ptr ( ) . cast :: < u64 > ( ) . read_unaligned ( ) ;
58
60
59
61
// FIXME the original code looks like this:
60
62
// error = ((locval & mask5) ^ fv) as u32;
@@ -70,14 +72,16 @@ pub fn is_valid_false_atom(loc: &[u8]) -> bool {
70
72
#[ cfg_attr( not( feature = "no-inline" ) , inline( always) ) ]
71
73
#[ allow( clippy:: cast_ptr_alignment, unused_unsafe) ]
72
74
pub fn is_valid_null_atom ( loc : & [ u8 ] ) -> bool {
75
+ debug_assert ! ( loc. len( ) >= 8 , "loc too short for a u64 read" ) ;
76
+
73
77
// TODO is this expensive?
74
78
let mut error: u64 ;
75
79
unsafe {
76
80
//let nv: u64 = *(b"null ".as_ptr() as *const u64);
77
81
// this is the same:
78
82
const NV : u64 = 0x00_00_00_00_6c_6c_75_6e ;
79
83
const MASK4 : u64 = 0x00_00_00_00_ff_ff_ff_ff ;
80
- let locval: u64 = * ( loc. as_ptr ( ) . cast :: < u64 > ( ) ) ;
84
+ let locval: u64 = loc. as_ptr ( ) . cast :: < u64 > ( ) . read_unaligned ( ) ;
81
85
82
86
error = ( locval & MASK4 ) ^ NV ;
83
87
error |= u64:: from ( is_not_structural_or_whitespace ( * get ! ( loc, 4 ) ) ) ;
0 commit comments