fn stable_read() {
    let operation = operation_from_args();
    let mut sum = 0;

    let repeat = operation.repeat.unwrap_or(1);
    let len = operation.size as u64;
    assert!(len <= STABLE_MEMORY_SIZE);
    for _ in 0..repeat {
        let dst = RNG.with(|rng| rng.borrow_mut().gen_range(0, STABLE_MEMORY_SIZE - len));
        MEMORY.with(|memory| {
            let mut refmut = memory.borrow_mut();
            #[allow(unused_assignments)]
            let mut buf = vec![].as_mut_slice();
            unsafe {
                buf = refmut.align_to_mut::<u8>().1;
            }
            // Always use the first part of `MEMORY` to minimize the number of different
            // pages touched. This should in turn minimize the overhead of wasm
            // memory operations when testing out stable memory operations.
            stable::stable64_read(buf, dst as u64, len as u64);
            #[allow(clippy::needless_range_loop)]
            for i in 0..len as usize {
                let value = buf[i];
                if let Some(expected_value) = operation.value {
                    if expected_value != value {
                        trap_with(&format!(
                            "Value mismatch at {}, expected {}, got {}",
                            i, expected_value, value
                        ));
                    }
                }
                sum += value;
            }
        });
    }

    api::reply(sum.to_string().as_bytes());
}
/// Reads and sums up all byte words in the given stable memory region.
///
/// Arguments:
/// - operation.repeat: the number of operations.
/// - operation.address: optional start address of the stable memory region. It
///   is chosen randomly if not given.
/// - operation.size: the size of the stable memory region in bytes.
/// - operation.value: optional byte value. If the value is given, then the
///   operation asserts that all read values match the given value.
Reads and sums up all byte words in the given stable memory region.
Arguments:
operation.repeat: the number of operations.
operation.address: optional start address of the stable memory region. It
is chosen randomly if not given.
operation.size: the size of the stable memory region in bytes.
Reads and sums up all byte words in the given stable memory region . Arguments : operation . repeat : the number of operations . operation . address : optional start address of the stable memory region . It is chosen randomly if not given . operation . size : the size of the stable memory region in bytes .
fn stable_read() {
    let operation = operation_from_args();
    let mut sum = 0;
    let repeat = operation.repeat.unwrap_or(1);
    let len = operation.size as u64;
    assert!(len <= STABLE_MEMORY_SIZE);
    for _ in 0..repeat {
        let dst = RNG.with(|rng| rng.borrow_mut().gen_range(0, STABLE_MEMORY_SIZE - len));
        MEMORY.with(|memory| {
            let mut refmut = memory.borrow_mut();
            #[allow(unused_assignments)]
            let mut buf = vec![].as_mut_slice();
            unsafe {
                buf = refmut.align_to_mut::<u8>().1;
            }
            // Always use the first part of `MEMORY` to minimize the number of different
            // pages touched. This should in turn minimize the overhead of wasm
            // memory operations when testing out stable memory operations.
            stable::stable64_read(buf, dst as u64, len as u64);
            #[allow(clippy::needless_range_loop)]
            for i in 0..len as usize {
                let value = buf[i];
                if let Some(expected_value) = operation.value {
                    if expected_value != value {
                        trap_with(&format!(
                            "Value mismatch at {}, expected {}, got {}",
                            i, expected_value, value
                        ));
                    }
                }
                sum += value;
            }
        });
    }
    api::reply(sum.to_string().as_bytes());
}
fn stable_read ( ) { let operation = operation_from_args ( ) ; let mut sum = 0 ; let repeat = operation . repeat . unwrap_or ( 1 ) ; let len = operation . size as u64 ; assert ! ( len STABLE_MEMORY_SIZE ) ; for _ in 0 .. repeat { let dst = RNG . with ( | rng | rng . borrow_mut ( ) . gen_range ( 0 , STABLE_MEMORY_SIZE - len ) ) ; MEMORY . with ( | memory | { let mut refmut = memory . borrow_mut ( ) ; # [ allow ( unused_assignments ) ] let mut buf = vec ! [ ] . as_mut_slice ( ) ; unsafe { buf = refmut . align_to_mut :: < u8 > ( ) . 1 ; } // Always use the first part of `MEMORY` to minimize the number of different // pages touched. This should in turn minimize the overhead of wasm // memory operations when testing out stable memory operations. stable :: stable64_read ( buf , dst as u64 , len as u64 ) ; # [ allow ( clippy needless_range_loop ) ] for i in 0 .. len as usize { let value = buf [ i ] ; if let Some ( expected_value ) = operation . value { if expected_value != value { trap_with ( & format ! ( " " i expected_value value ) ) ; } } sum += value ; } } ) ; } api :: reply ( sum . to_string ( ) . as_bytes ( ) ) ; }
Reads and sums up all byte words in the given stable memory region.
Reads and sums up all byte words in the given stable memory region .