From db15596c5747eed0344f2622a9d85ad9534b23f9 Mon Sep 17 00:00:00 2001 From: Sergio Benitez Date: Thu, 22 Oct 2020 03:22:13 -0700 Subject: [PATCH] Only load LOCAL_STREAMS if they are being used --- library/std/src/io/stdio.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/library/std/src/io/stdio.rs b/library/std/src/io/stdio.rs index 5b50ce4c2ee..2eb5fb45286 100644 --- a/library/std/src/io/stdio.rs +++ b/library/std/src/io/stdio.rs @@ -963,6 +963,11 @@ pub fn set_print(sink: Option>) -> Option (Option>, Option>) { + // Don't waste time when LOCAL_{STDOUT,STDERR} are definitely None. + if !LOCAL_STREAMS.load(Ordering::Relaxed) { + return (None, None); + } + LOCAL_STDOUT.with(|stdout| { LOCAL_STDERR.with(|stderr| { (