Skip to content

Commit

Permalink
Switch to vector for capture mapping
Browse files Browse the repository at this point in the history
The order of the captures matters for the order of the resulting
scope stack. It would also work with a BTreeMap but since we only
ever iterate it in order, a Vec is probably faster/better.
  • Loading branch information
trishume committed Apr 4, 2017
1 parent 34a6b85 commit 09efd6f
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 7 deletions.
Binary file modified assets/default_newlines.packdump
Binary file not shown.
Binary file modified assets/default_nonewlines.packdump
Binary file not shown.
4 changes: 2 additions & 2 deletions src/parsing/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,8 @@ impl ParseState {
// ex: ((bob)|(hi))* could match hibob in wrong order, and outer has to push first
// we don't have to handle a capture matching multiple times, Sublime doesn't
let mut map: Vec<((usize, i32), ScopeStackOp)> = Vec::new();
for (cap_index, scopes) in capture_map.iter() {
if let Some((cap_start, cap_end)) = reg_match.regions.pos(*cap_index) {
for &(cap_index, ref scopes) in capture_map.iter() {
if let Some((cap_start, cap_end)) = reg_match.regions.pos(cap_index) {
// marking up empty captures causes pops to be sorted wrong
if cap_start == cap_end {
continue;
Expand Down
2 changes: 1 addition & 1 deletion src/parsing/syntax_definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use super::scope::*;
use regex_syntax::escape;
use rustc_serialize::{Encodable, Encoder, Decodable, Decoder};

pub type CaptureMapping = HashMap<usize, Vec<Scope>>;
pub type CaptureMapping = Vec<(usize, Vec<Scope>)>;
pub type ContextPtr = Rc<RefCell<Context>>;

/// The main data structure representing a syntax definition loaded from a
Expand Down
8 changes: 4 additions & 4 deletions src/parsing/yaml_load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,11 +276,11 @@ impl SyntaxDefinition {
.unwrap_or_else(|| Ok(vec![])));

let captures = if let Ok(map) = get_key(map, "captures", |x| x.as_hash()) {
let mut res_map = HashMap::new();
let mut res_map = Vec::new();
for (key, value) in map.iter() {
if let (Some(key_int), Some(val_str)) = (key.as_i64(), value.as_str()) {
res_map.insert(key_int as usize,
try!(str_to_scopes(val_str, state.scope_repo)));
res_map.push((key_int as usize,
try!(str_to_scopes(val_str, state.scope_repo))));
}
}
Some(res_map)
Expand Down Expand Up @@ -405,7 +405,7 @@ mod tests {
match first_pattern {
&Pattern::Match(ref match_pat) => {
let m: &CaptureMapping = match_pat.captures.as_ref().expect("test failed");
assert_eq!(&m[&1], &vec![Scope::new("meta.preprocessor.c++").unwrap()]);
assert_eq!(&m[0], &(1,vec![Scope::new("meta.preprocessor.c++").unwrap()]));
use parsing::syntax_definition::ContextReference::*;

// this is sadly necessary because Context is not Eq because of the Regex
Expand Down

0 comments on commit 09efd6f

Please sign in to comment.