Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce allocations in SelectorMap (Rule Hash) code #1299

Merged
merged 5 commits into from Nov 22, 2013

Eliminate use of `map` by using a for loop.

  • Loading branch information
pradeep90 committed Nov 22, 2013
commit 92f4a430ea163af3d4ab969b8a1d919ccb287d79
@@ -304,8 +304,14 @@ impl Stylist {

// Keeping this as a separate step because we will need it for further
// optimizations regarding grouping of Rules having the same Selector.
let declarations_list = matching_rules_list.map(
|rules| rules.map(|r| r.declarations.clone()));
let mut declarations_list = ~[];
for rules in matching_rules_list.iter() {
declarations_list.push(~[]);
let curr_declarations = &mut declarations_list[declarations_list.len() - 1];

This comment has been minimized.

@pcwalton

pcwalton Nov 22, 2013

Contributor

nit: I doubt it makes a difference, but this will be slightly faster and clearer (avoids the bounds check) if you just do:

let mut curr_declarations = ~[];
for rule in rules.iter() { ... }
declarations_list.push(curr_declarations);

The push does a move of curr_declarations so it won't copy.

for rule in rules.iter() {
curr_declarations.push(rule.declarations.clone());
}
}

let mut applicable_declarations = ~[];
applicable_declarations.push_all_move(declarations_list.slice(0, 3).concat_vec());
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.