Skip to content

Commit 01eb50f

Browse files
committed
Eliminate more unaligned reads and writes where unnecessary.
1 parent 02435df commit 01eb50f

File tree

3 files changed

+4
-7
lines changed

3 files changed

+4
-7
lines changed

src/interpreter/builtins/vm.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use std::mem::transmute;
2-
use std::ptr::read_unaligned;
32
use std::rc::Rc;
43
use std::str::FromStr;
54
use monoteny_macro::{pop_ip, un_expr, un_expr_try};

src/interpreter/data.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
use std::alloc::{alloc, Layout};
22
use std::intrinsics::transmute;
3-
use std::ptr::write_unaligned;
43
use uuid::Uuid;
5-
use crate::program::types::TypeProto;
64

75
#[derive(Copy, Clone)]
86
pub union Value {
@@ -29,12 +27,12 @@ impl Value {
2927
// TODO The constants should probably be alloced in the chunk's constants, not 'anywhere'.
3028
pub unsafe fn string_to_ptr(string: &String) -> *mut () {
3129
let data = alloc(Layout::new::<String>());
32-
write_unaligned(data as *mut String, string.clone());
30+
*(data as *mut String) = string.clone();
3331
transmute(data)
3432
}
3533

3634
pub unsafe fn uuid_to_ptr(uuid: Uuid) -> *mut () {
3735
let data = alloc(Layout::new::<Uuid>());
38-
write_unaligned(data as *mut Uuid, uuid);
36+
*(data as *mut Uuid) = uuid;
3937
transmute(data)
4038
}

src/interpreter/vm.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -401,15 +401,15 @@ impl VM {
401401
let sp_last = sp.offset(-8);
402402
let slot_ptr = (*sp_last).ptr.byte_add(usize::try_from(slot_idx).unwrap() * 8);
403403

404-
*sp_last = read_unaligned(slot_ptr as *mut Value);
404+
*sp_last = *(slot_ptr as *mut Value);
405405
}
406406
OpCode::SET_MEMBER_32 => {
407407
let slot_idx = pop_ip!(u32);
408408
let value = pop_stack(&mut sp);
409409
let obj_ptr = pop_stack(&mut sp).ptr;
410410
let slot_ptr = obj_ptr.byte_add(usize::try_from(slot_idx).unwrap() * 8);
411411

412-
write_unaligned(slot_ptr as *mut Value, value);
412+
*(slot_ptr as *mut Value) = value;
413413
}
414414
}
415415
}

0 commit comments

Comments
 (0)