From 4b18fff2be74df9a2db5ee6ab418da322ad6ae18 Mon Sep 17 00:00:00 2001 From: Huon Wilson Date: Fri, 14 Jun 2013 01:39:06 +1000 Subject: std: convert str::{map,levdistance,subslice_offset} to methods. The first two become map_chars and lev_distance. Also, remove a few allocations in rustdoc. --- src/libsyntax/parse/comments.rs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'src/libsyntax/parse') diff --git a/src/libsyntax/parse/comments.rs b/src/libsyntax/parse/comments.rs index 68473f11537..82a7b55eeee 100644 --- a/src/libsyntax/parse/comments.rs +++ b/src/libsyntax/parse/comments.rs @@ -89,12 +89,11 @@ pub fn strip_doc_comment_decoration(comment: &str) -> ~str { } return do lines.map |line| { - let mut chars = ~[]; - for line.iter().advance |c| { chars.push(c) } + let chars = line.iter().collect::<~[char]>(); if i > chars.len() { ~"" } else { - str::from_chars(chars.slice(i, chars.len()).to_owned()) + str::from_chars(chars.slice(i, chars.len())) } }; } @@ -103,14 +102,13 @@ pub fn strip_doc_comment_decoration(comment: &str) -> ~str { // FIXME #5475: // return comment.slice(3u, comment.len()).trim().to_owned(); let r = comment.slice(3u, comment.len()); return r.trim().to_owned(); - } if comment.starts_with("/*") { - let mut lines = ~[]; - for str::each_line_any(comment.slice(3u, comment.len() - 2u)) |line| { - lines.push(line.to_owned()) - } + let lines = comment.slice(3u, comment.len() - 2u) + .any_line_iter() + .transform(|s| s.to_owned()) + .collect::<~[~str]>(); let lines = vertical_trim(lines); let lines = block_trim(lines, ~"\t ", None); let lines = block_trim(lines, ~"*", Some(1u)); -- cgit 1.4.1-3-g733a5