Skip to content

Commit f5199ac

Browse files
committed
Do writing via io::stdout
According to the benchmarks this is actually faster.
1 parent 84d0f10 commit f5199ac

File tree

2 files changed

+3
-62
lines changed

2 files changed

+3
-62
lines changed

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ timestamp = ["chrono"]
2626

2727
[dependencies]
2828
chrono = { version = "0.4", optional = true }
29-
libc = { version = "0.2.58" }
3029
log = { version = "0.4.8", features = ["std", "kv_unstable"] }
3130
log-panics = { version = "2", optional = true, features = ["with-backtrace"] }
3231

src/lib.rs

Lines changed: 3 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -406,65 +406,10 @@ fn log_failure(err: io::Error) {
406406
// though the return type of the functions are different we only need them both
407407
// to implement `io::Write`.
408408

409+
#[cfg(test)]
410+
use self::test_instruments::{stderr, stdout, LOG_OUTPUT, LOG_OUTPUT_INDEX};
409411
#[cfg(not(test))]
410-
struct Stdout;
411-
412-
#[cfg(not(test))]
413-
impl Write for Stdout {
414-
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
415-
match unsafe {
416-
libc::write(
417-
libc::STDOUT_FILENO,
418-
buf.as_ptr() as *const libc::c_void,
419-
buf.len(),
420-
)
421-
} {
422-
n if n < 0 => Err(io::Error::last_os_error()),
423-
n => Ok(n as usize),
424-
}
425-
}
426-
427-
fn flush(&mut self) -> io::Result<()> {
428-
// Don't have to flush standard out.
429-
Ok(())
430-
}
431-
}
432-
433-
#[cfg(not(test))]
434-
#[inline(always)]
435-
fn stdout() -> Stdout {
436-
Stdout
437-
}
438-
439-
#[cfg(not(test))]
440-
struct Stderr;
441-
442-
#[cfg(not(test))]
443-
impl Write for Stderr {
444-
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
445-
match unsafe {
446-
libc::write(
447-
libc::STDERR_FILENO,
448-
buf.as_ptr() as *const libc::c_void,
449-
buf.len(),
450-
)
451-
} {
452-
n if n < 0 => Err(io::Error::last_os_error()),
453-
n => Ok(n as usize),
454-
}
455-
}
456-
457-
fn flush(&mut self) -> io::Result<()> {
458-
// Don't have to flush standard error.
459-
Ok(())
460-
}
461-
}
462-
463-
#[cfg(not(test))]
464-
#[inline(always)]
465-
fn stderr() -> Stderr {
466-
Stderr
467-
}
412+
use std::io::{stderr, stdout};
468413

469414
// The testing variant of the functions.
470415

@@ -536,6 +481,3 @@ mod test_instruments {
536481
}
537482
}
538483
}
539-
540-
#[cfg(test)]
541-
use self::test_instruments::{stderr, stdout, LOG_OUTPUT, LOG_OUTPUT_INDEX};

0 commit comments

Comments
 (0)