From 6c29708bf906fa9075bb96b76fd7f6cc81eda43c Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 20 Jan 2015 10:45:29 -0800 Subject: regex: Remove in-tree version The regex library was largely used for non-critical aspects of the compiler and various external tooling. The library at this point is duplicated with its out-of-tree counterpart and as such imposes a bit of a maintenance overhead as well as compile time hit for the compiler itself. The last major user of the regex library is the libtest library, using regexes for filters when running tests. This removal means that the filtering has gone back to substring matching rather than using regexes. --- src/liblog/directive.rs | 15 ++------------- src/liblog/lib.rs | 24 ++++++++++-------------- 2 files changed, 12 insertions(+), 27 deletions(-) (limited to 'src/liblog') diff --git a/src/liblog/directive.rs b/src/liblog/directive.rs index d741019aa7b..5efa799f562 100644 --- a/src/liblog/directive.rs +++ b/src/liblog/directive.rs @@ -8,7 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use regex::Regex; use std::ascii::AsciiExt; use std::cmp; @@ -34,7 +33,7 @@ fn parse_log_level(level: &str) -> Option { /// /// Valid log levels are 0-255, with the most likely ones being 1-4 (defined in /// std::). Also supports string log levels of error, warn, info, and debug -pub fn parse_logging_spec(spec: &str) -> (Vec, Option) { +pub fn parse_logging_spec(spec: &str) -> (Vec, Option) { let mut dirs = Vec::new(); let mut parts = spec.split('/'); @@ -80,17 +79,7 @@ pub fn parse_logging_spec(spec: &str) -> (Vec, Option) { }); }}); - let filter = filter.map_or(None, |filter| { - match Regex::new(filter) { - Ok(re) => Some(re), - Err(e) => { - println!("warning: invalid regex filter - {:?}", e); - None - } - } - }); - - return (dirs, filter); + (dirs, filter.map(|s| s.to_string())) } #[cfg(test)] diff --git a/src/liblog/lib.rs b/src/liblog/lib.rs index 4da07c50c59..e7c5bc35f76 100644 --- a/src/liblog/lib.rs +++ b/src/liblog/lib.rs @@ -123,11 +123,11 @@ //! //! # Filtering results //! -//! A RUST_LOG directive may include a regex filter. The syntax is to append `/` -//! followed by a regex. Each message is checked against the regex, and is only -//! logged if it matches. Note that the matching is done after formatting the log -//! string but before adding any logging meta-data. There is a single filter for all -//! modules. +//! A RUST_LOG directive may include a string filter. The syntax is to append +//! `/` followed by a string. Each message is checked against the string and is +//! only logged if it contains the string. Note that the matching is done after +//! formatting the log string but before adding any logging meta-data. There is +//! a single filter for all modules. //! //! Some examples: //! @@ -172,8 +172,6 @@ #![allow(unstable)] #![deny(missing_docs)] -extern crate regex; - use std::cell::RefCell; use std::fmt; use std::io::LineBufferedWriter; @@ -185,8 +183,6 @@ use std::rt; use std::slice; use std::sync::{Once, ONCE_INIT}; -use regex::Regex; - use directive::LOG_LEVEL_NAMES; #[macro_use] @@ -209,8 +205,8 @@ static mut LOG_LEVEL: u32 = MAX_LOG_LEVEL; static mut DIRECTIVES: *const Vec = 0 as *const Vec; -/// Optional regex filter. -static mut FILTER: *const Regex = 0 as *const _; +/// Optional filter. +static mut FILTER: *const String = 0 as *const _; /// Debug log level pub const DEBUG: u32 = 4; @@ -288,7 +284,7 @@ pub fn log(level: u32, loc: &'static LogLocation, args: fmt::Arguments) { // Test the literal string from args against the current filter, if there // is one. match unsafe { FILTER.as_ref() } { - Some(filter) if !filter.is_match(&args.to_string()[]) => return, + Some(filter) if !args.to_string().contains(&filter[]) => return, _ => {} } @@ -435,8 +431,8 @@ fn init() { DIRECTIVES = ptr::null(); if !FILTER.is_null() { - let _filter: Box = mem::transmute(FILTER); - FILTER = ptr::null(); + let _filter: Box = mem::transmute(FILTER); + FILTER = 0 as *const _; } }); } -- cgit 1.4.1-3-g733a5