prevent cursor r/w optimization
This commit is contained in:
parent
7d6d40a785
commit
81eba30a29
@ -2,6 +2,7 @@
|
||||
use alloc::vec::Vec;
|
||||
|
||||
use core_io::{Error as IoError, Read, Write};
|
||||
use core::arch::asm;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Cursor<T> {
|
||||
@ -47,6 +48,7 @@ impl<T: AsRef<[u8]>> Read for Cursor<T> {
|
||||
let len = buf.len().min(data.len());
|
||||
// ``copy_from_slice`` generates AXI bursts, use a regular loop instead
|
||||
for i in 0..len {
|
||||
unsafe { asm!("", options(preserves_flags, nostack, readonly)); }
|
||||
buf[i] = data[i];
|
||||
}
|
||||
self.pos += len;
|
||||
@ -59,6 +61,7 @@ impl Write for Cursor<&mut [u8]> {
|
||||
let data = &mut self.inner[self.pos..];
|
||||
let len = buf.len().min(data.len());
|
||||
for i in 0..len {
|
||||
unsafe { asm!("", options(preserves_flags, nostack, readonly)); }
|
||||
data[i] = buf[i];
|
||||
}
|
||||
self.pos += len;
|
||||
|
@ -1,5 +1,6 @@
|
||||
#![no_std]
|
||||
#![feature(never_type)]
|
||||
#![feature(asm)]
|
||||
|
||||
#[cfg(feature = "alloc")]
|
||||
extern crate alloc;
|
||||
|
Loading…
Reference in New Issue
Block a user