mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-12 17:37:53 +03:00
cp: Try to pre-size the destination file to the final size up front
Since we usually know how many bytes we're going to write, we can be nice to the kernel and ftruncate() the destination to the expected size up front, reducing the amount of FS churn.
This commit is contained in:
parent
845094f9e4
commit
f9d679ae37
Notes:
sideshowbarker
2024-07-19 11:28:50 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/f9d679ae37a
@ -89,6 +89,11 @@ bool copy_file(String src_path, String dst_path, struct stat src_stat, int src_f
|
||||
}
|
||||
}
|
||||
|
||||
if (src_stat.st_size > 0) {
|
||||
// NOTE: This is primarily an optimization, so it's not the end if it fails.
|
||||
ftruncate(dst_fd, src_stat.st_size);
|
||||
}
|
||||
|
||||
for (;;) {
|
||||
char buffer[BUFSIZ];
|
||||
ssize_t nread = read(src_fd, buffer, sizeof(buffer));
|
||||
@ -151,4 +156,4 @@ bool copy_directory(String src_path, String dst_path)
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user