]> git.lizzy.rs Git - rust.git/blobdiff - src/shims/intrinsics.rs
rustup: more flexible write_bytes avoids allocations and removes itertools dependency
[rust.git] / src / shims / intrinsics.rs
index 46658760cc12ac36b50b873d08bcc2687cc78265..5ef7fba7f59083b093902b40a094b4b2fe851d95 100644 (file)
@@ -1,3 +1,5 @@
+use std::iter;
+
 use rustc_apfloat::Float;
 use rustc::mir;
 use rustc::mir::interpret::{InterpResult, PointerArithmetic};
@@ -356,11 +358,8 @@ fn call_intrinsic(
                         _ => {
                             // Do it in memory
                             let mplace = this.force_allocation(dest)?;
-                            mplace.meta.unwrap_none();
-                            // not a zst, must be valid pointer
-                            let ptr = mplace.ptr.to_ptr()?;
-                            // we know the return place is in-bounds
-                            this.memory.get_mut(ptr.alloc_id)?.write_repeat(tcx, ptr, 0, dest.layout.size)?;
+                            mplace.meta.unwrap_none(); // must be sized
+                            this.memory.write_bytes(mplace.ptr, iter::repeat(0u8).take(dest.layout.size.bytes() as usize))?;
                         }
                     }
                 }
@@ -565,16 +564,7 @@ fn call_intrinsic(
                 let ptr = this.read_scalar(args[0])?.not_undef()?;
                 let count = this.read_scalar(args[2])?.to_usize(this)?;
                 let byte_count = ty_layout.size * count;
-                match this.memory.check_ptr_access(ptr, byte_count, ty_layout.align.abi)? {
-                    Some(ptr) => {
-                        this.memory
-                            .get_mut(ptr.alloc_id)?
-                            .write_repeat(tcx, ptr, val_byte, byte_count)?;
-                    }
-                    None => {
-                        // Size is 0, nothing to do.
-                    }
-                }
+                this.memory.write_bytes(ptr, iter::repeat(val_byte).take(byte_count.bytes() as usize))?;
             }
 
             name => throw_unsup_format!("unimplemented intrinsic: {}", name),