Skip to content

Commit 6f571a6

Browse files
committed
libglob -- patch closure where const borrow would have helped
1 parent 96139bf commit 6f571a6

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/libglob/lib.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#[crate_type = "dylib"];
2929
#[license = "MIT/ASL2"];
3030

31+
use std::cell::Cell;
3132
use std::{os, path};
3233
use std::io::fs;
3334
use std::path::is_sep;
@@ -342,22 +343,24 @@ impl Pattern {
342343
}
343344

344345
fn matches_from(&self,
345-
mut prev_char: Option<char>,
346+
prev_char: Option<char>,
346347
mut file: &str,
347348
i: uint,
348349
options: MatchOptions) -> MatchResult {
349350

351+
let prev_char = Cell::new(prev_char);
352+
350353
let require_literal = |c| {
351354
(options.require_literal_separator && is_sep(c)) ||
352355
(options.require_literal_leading_dot && c == '.'
353-
&& is_sep(prev_char.unwrap_or('/')))
356+
&& is_sep(prev_char.get().unwrap_or('/')))
354357
};
355358

356359
for (ti, token) in self.tokens.slice_from(i).iter().enumerate() {
357360
match *token {
358361
AnySequence => {
359362
loop {
360-
match self.matches_from(prev_char, file, i + ti + 1, options) {
363+
match self.matches_from(prev_char.get(), file, i + ti + 1, options) {
361364
SubPatternDoesntMatch => (), // keep trying
362365
m => return m,
363366
}
@@ -370,7 +373,7 @@ impl Pattern {
370373
if require_literal(c) {
371374
return SubPatternDoesntMatch;
372375
}
373-
prev_char = Some(c);
376+
prev_char.set(Some(c));
374377
file = next;
375378
}
376379
}
@@ -400,7 +403,7 @@ impl Pattern {
400403
if !matches {
401404
return SubPatternDoesntMatch;
402405
}
403-
prev_char = Some(c);
406+
prev_char.set(Some(c));
404407
file = next;
405408
}
406409
}

0 commit comments

Comments
 (0)