diff options
| author | Niko Matsakis <niko@alum.mit.edu> | 2014-02-07 06:38:53 -0500 |
|---|---|---|
| committer | Niko Matsakis <niko@alum.mit.edu> | 2014-02-11 16:55:22 -0500 |
| commit | 6f571a63a6e966ae59e0d078542c04734eba58ac (patch) | |
| tree | 5b652080a24634c52159d22ef83372558b17caa0 /src/libglob | |
| parent | 96139bf1d6eb00d60e8f6521dbf56fc23286723f (diff) | |
| download | rust-6f571a63a6e966ae59e0d078542c04734eba58ac.tar.gz rust-6f571a63a6e966ae59e0d078542c04734eba58ac.zip | |
libglob -- patch closure where const borrow would have helped
Diffstat (limited to 'src/libglob')
| -rw-r--r-- | src/libglob/lib.rs | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/src/libglob/lib.rs b/src/libglob/lib.rs index c6ecb7697da..25634b1808d 100644 --- a/src/libglob/lib.rs +++ b/src/libglob/lib.rs @@ -28,6 +28,7 @@ #[crate_type = "dylib"]; #[license = "MIT/ASL2"]; +use std::cell::Cell; use std::{os, path}; use std::io::fs; use std::path::is_sep; @@ -342,22 +343,24 @@ impl Pattern { } fn matches_from(&self, - mut prev_char: Option<char>, + prev_char: Option<char>, mut file: &str, i: uint, options: MatchOptions) -> MatchResult { + let prev_char = Cell::new(prev_char); + let require_literal = |c| { (options.require_literal_separator && is_sep(c)) || (options.require_literal_leading_dot && c == '.' - && is_sep(prev_char.unwrap_or('/'))) + && is_sep(prev_char.get().unwrap_or('/'))) }; for (ti, token) in self.tokens.slice_from(i).iter().enumerate() { match *token { AnySequence => { loop { - match self.matches_from(prev_char, file, i + ti + 1, options) { + match self.matches_from(prev_char.get(), file, i + ti + 1, options) { SubPatternDoesntMatch => (), // keep trying m => return m, } @@ -370,7 +373,7 @@ impl Pattern { if require_literal(c) { return SubPatternDoesntMatch; } - prev_char = Some(c); + prev_char.set(Some(c)); file = next; } } @@ -400,7 +403,7 @@ impl Pattern { if !matches { return SubPatternDoesntMatch; } - prev_char = Some(c); + prev_char.set(Some(c)); file = next; } } |
