librustc: Remove some string allocations. rs=perf

This commit is contained in:
Patrick Walton
2013-01-05 19:33:37 -08:00
parent 1070cc0109
commit fa96740923
5 changed files with 97 additions and 85 deletions

View File

@@ -178,15 +178,15 @@ fn get_name_value_str_pair(item: @ast::meta_item) -> Option<(~str, ~str)> {
/* Searching */
/// Search a list of attributes and return only those with a specific name
fn find_attrs_by_name(attrs: ~[ast::attribute], name: ~str) ->
fn find_attrs_by_name(attrs: ~[ast::attribute], name: &str) ->
~[ast::attribute] {
let filter = (
fn@(a: &ast::attribute) -> Option<ast::attribute> {
if get_attr_name(*a) == name {
option::Some(*a)
} else { option::None }
let filter: &fn(a: &ast::attribute) -> Option<ast::attribute> = |a| {
if name == get_attr_name(*a) {
option::Some(*a)
} else {
option::None
}
);
};
return vec::filter_map(attrs, filter);
}