diff options
| author | Kevin Ballard <kevin@sb.org> | 2013-07-11 00:56:26 -0700 |
|---|---|---|
| committer | Kevin Ballard <kevin@sb.org> | 2013-07-14 15:01:50 -0700 |
| commit | 1d4c3146f5e35ce60db73849da8806d73c6ecee2 (patch) | |
| tree | ce10236b81d0859222b0fa9125ef6f3753e3d496 /src/libsyntax | |
| parent | 69da3808444d71a39d3c05519a45d5186537cfcb (diff) | |
| download | rust-1d4c3146f5e35ce60db73849da8806d73c6ecee2.tar.gz rust-1d4c3146f5e35ce60db73849da8806d73c6ecee2.zip | |
Don't re-parse terminfo (twice!) on every compiler diagnostic
Stuff the term::Terminal into TLS to avoid re-parsing for every single message we want to color. Fixes #6827.
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/diagnostic.rs | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/src/libsyntax/diagnostic.rs b/src/libsyntax/diagnostic.rs index fc0dc4c8f52..2971ad5cc29 100644 --- a/src/libsyntax/diagnostic.rs +++ b/src/libsyntax/diagnostic.rs @@ -13,6 +13,7 @@ use codemap; use std::io; use std::uint; +use std::local_data; use extra::term; pub type Emitter = @fn(cmsp: Option<(@codemap::CodeMap, span)>, @@ -187,13 +188,29 @@ fn diagnosticcolor(lvl: level) -> term::color::Color { } fn print_maybe_styled(msg: &str, color: term::attr::Attr) { + #[cfg(not(stage0))] + static tls_terminal: local_data::Key<@Option<term::Terminal>> = &local_data::Key; + #[cfg(stage0)] + fn tls_terminal(_: @Option<term::Terminal>) {} + let stderr = io::stderr(); if stderr.get_type() == io::Screen { - let t = term::Terminal::new(stderr); + let t = match local_data::get(tls_terminal, |v| v.map_consume(|&k|k)) { + None => { + let t = term::Terminal::new(stderr); + let tls = @match t { + Ok(t) => Some(t), + Err(_) => None + }; + local_data::set(tls_terminal, tls); + &*tls + } + Some(tls) => &*tls + }; match t { - Ok(term) => { + &Some(ref term) => { term.attr(color); stderr.write_str(msg); term.reset(); |
