mirror of
https://github.com/uutils/coreutils.git
synced 2026-06-10 15:48:22 -07:00
cat: remove splice.rs
This commit is contained in:
@@ -23,10 +23,6 @@ use uucore::error::{UResult, strip_errno};
|
||||
use uucore::translate;
|
||||
use uucore::{fast_inc::fast_inc_one, format_usage};
|
||||
|
||||
/// Linux splice support
|
||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||
mod splice;
|
||||
|
||||
// Allocate 32 digits for the line number.
|
||||
// An estimate is that we can print about 1e8 lines/seconds, so 32 digits
|
||||
// would be enough for billions of universe lifetimes.
|
||||
@@ -483,14 +479,14 @@ fn print_fast<R: FdReadable>(handle: &mut InputHandle<R>) -> CatResult<()> {
|
||||
let stdout = io::stdout();
|
||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||
let mut stdout = stdout;
|
||||
// Try to use the splice() system call for faster writing. If it works, we're done.
|
||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||
if !uucore::pipes::splice_unbounded_auto(&handle.reader, &mut stdout)?
|
||||
&& !uucore::pipes::might_fuse(&handle.reader)
|
||||
{
|
||||
// If we're on Linux or Android, try to use the splice() system call
|
||||
// for faster writing. If it works, we're done.
|
||||
if !splice::write_fast_using_splice(handle, &mut stdout)? {
|
||||
return Ok(());
|
||||
}
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
// If we're not on Linux or Android, or the splice() call failed,
|
||||
// fall back on slower writing.
|
||||
print_unbuffered(handle, stdout)
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
// This file is part of the uutils coreutils package.
|
||||
//
|
||||
// For the full copyright and license information, please view the LICENSE
|
||||
// file that was distributed with this source code.
|
||||
use super::{CatResult, FdReadable, InputHandle};
|
||||
|
||||
use std::os::fd::AsFd;
|
||||
|
||||
use uucore::pipes::{MAX_ROOTLESS_PIPE_SIZE, might_fuse, splice};
|
||||
|
||||
/// This function is called from `write_fast()` on Linux and Android. The
|
||||
/// function `splice()` is used to move data between two file descriptors
|
||||
/// without copying between kernel and user spaces. This results in a large
|
||||
/// speedup.
|
||||
///
|
||||
/// The `bool` in the result value indicates if we need to fall back to normal
|
||||
/// copying or not. False means we don't have to.
|
||||
#[inline]
|
||||
pub(super) fn write_fast_using_splice<R: FdReadable, S: AsFd>(
|
||||
handle: &InputHandle<R>,
|
||||
write_fd: &mut S,
|
||||
) -> CatResult<bool> {
|
||||
let res = match splice(&handle.reader, &write_fd, MAX_ROOTLESS_PIPE_SIZE) {
|
||||
Ok(_) => uucore::pipes::splice_unbounded(&handle.reader, write_fd)?,
|
||||
// both of in/output are not pipe
|
||||
_ => uucore::pipes::splice_unbounded_broker(&handle.reader, write_fd)?,
|
||||
};
|
||||
Ok(res || might_fuse(&handle.reader))
|
||||
}
|
||||
@@ -146,6 +146,25 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
/// try splice_unbounded 1st and splice_unbounded_broker if both of in/output are not pipe
|
||||
///
|
||||
/// return true if write fallback is needed
|
||||
/// (the fallback will be embedded to this function in the future)
|
||||
#[inline]
|
||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||
pub fn splice_unbounded_auto<R, S>(source: &R, dest: &mut S) -> std::io::Result<bool>
|
||||
where
|
||||
R: Read + AsFd,
|
||||
S: AsFd,
|
||||
{
|
||||
// use splice to check that input or output is pipe which is efficient
|
||||
let fallback = match splice(&source, dest, MAX_ROOTLESS_PIPE_SIZE) {
|
||||
Ok(_) => splice_unbounded(source, dest)?,
|
||||
_ => splice_unbounded_broker(source, dest)?,
|
||||
};
|
||||
Ok(fallback)
|
||||
}
|
||||
|
||||
/// splice `n` bytes with safe read/write fallback
|
||||
/// return actually sent bytes
|
||||
#[inline]
|
||||
|
||||
Reference in New Issue
Block a user