summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNicolas Koch <nioko1337@gmail.com>2018-05-24 14:51:59 +0200
committerNicolas Koch <nioko1337@gmail.com>2018-05-24 14:51:59 +0200
commit3f392abdfb2ec0f436352d349eedd5f6707bf817 (patch)
treead68babe6962075b833548d82f9eeab2ad528c14
parentStore ENOSYS in a global to avoid unnecessary system calls (diff)
downloadgrust-3f392abdfb2ec0f436352d349eedd5f6707bf817.tar.gz
grust-3f392abdfb2ec0f436352d349eedd5f6707bf817.tar.bz2
grust-3f392abdfb2ec0f436352d349eedd5f6707bf817.tar.xz
Implement suggestions from the PR
- Move loading of atomic bool outside the loop - Add comment about TryFrom for future improvement
-rw-r--r--src/libstd/sys/unix/fs.rs4
1 files changed, 3 insertions, 1 deletions
diff --git a/src/libstd/sys/unix/fs.rs b/src/libstd/sys/unix/fs.rs
index 8412540934..6624c48cbe 100644
--- a/src/libstd/sys/unix/fs.rs
+++ b/src/libstd/sys/unix/fs.rs
@@ -818,14 +818,16 @@ pub fn copy(from: &Path, to: &Path) -> io::Result<u64> {
818 (metadata.permissions(), metadata.size()) 818 (metadata.permissions(), metadata.size())
819 }; 819 };
820 820
821 let has_copy_file_range = HAS_COPY_FILE_RANGE.load(Ordering::Relaxed);
821 let mut written = 0u64; 822 let mut written = 0u64;
822 while written < len { 823 while written < len {
824 // TODO should ideally use TryFrom
823 let bytes_to_copy = if len - written > usize::max_value() as u64 { 825 let bytes_to_copy = if len - written > usize::max_value() as u64 {
824 usize::max_value() 826 usize::max_value()
825 } else { 827 } else {
826 (len - written) as usize 828 (len - written) as usize
827 }; 829 };
828 let copy_result = if HAS_COPY_FILE_RANGE.load(Ordering::Relaxed) { 830 let copy_result = if has_copy_file_range {
829 let copy_result = unsafe { 831 let copy_result = unsafe {
830 // We actually don't have to adjust the offsets, 832 // We actually don't have to adjust the offsets,
831 // because copy_file_range adjusts the file offset automatically 833 // because copy_file_range adjusts the file offset automatically