Skip to content

Commit 9ba91e1

Browse files
committed
librustdoc: Remove all ~str usage from librustdoc.
1 parent 6559a36 commit 9ba91e1

File tree

13 files changed

+357
-261
lines changed

13 files changed

+357
-261
lines changed

src/librustdoc/clean.rs

Lines changed: 70 additions & 62 deletions
Large diffs are not rendered by default.

src/librustdoc/core.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ pub enum MaybeTyped {
3232
}
3333

3434
pub type ExternalPaths = RefCell<Option<HashMap<ast::DefId,
35-
(Vec<~str>, clean::TypeKind)>>>;
35+
(Vec<StrBuf>, clean::TypeKind)>>>;
3636

3737
pub struct DocContext {
3838
pub krate: ast::Crate,
@@ -57,7 +57,7 @@ pub struct CrateAnalysis {
5757
}
5858

5959
/// Parses, resolves, and typechecks the given crate
60-
fn get_ast_and_resolve(cpath: &Path, libs: HashSet<Path>, cfgs: Vec<~str>)
60+
fn get_ast_and_resolve(cpath: &Path, libs: HashSet<Path>, cfgs: Vec<StrBuf>)
6161
-> (DocContext, CrateAnalysis) {
6262
use syntax::codemap::dummy_spanned;
6363
use rustc::driver::driver::{FileInput,
@@ -88,7 +88,7 @@ fn get_ast_and_resolve(cpath: &Path, libs: HashSet<Path>, cfgs: Vec<~str>)
8888

8989
let mut cfg = build_configuration(&sess);
9090
for cfg_ in cfgs.move_iter() {
91-
let cfg_ = token::intern_and_get_ident(cfg_);
91+
let cfg_ = token::intern_and_get_ident(cfg_.as_slice());
9292
cfg.push(@dummy_spanned(ast::MetaWord(cfg_)));
9393
}
9494

@@ -112,7 +112,7 @@ fn get_ast_and_resolve(cpath: &Path, libs: HashSet<Path>, cfgs: Vec<~str>)
112112
})
113113
}
114114

115-
pub fn run_core(libs: HashSet<Path>, cfgs: Vec<~str>, path: &Path)
115+
pub fn run_core(libs: HashSet<Path>, cfgs: Vec<StrBuf>, path: &Path)
116116
-> (clean::Crate, CrateAnalysis) {
117117
let (ctxt, analysis) = get_ast_and_resolve(path, libs, cfgs);
118118
let ctxt = @ctxt;

src/librustdoc/html/format.rs

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,13 @@ fn resolved_path(w: &mut io::Writer, did: ast::DefId, p: &clean::Path,
151151
path(w, p, print_all,
152152
|cache, loc| {
153153
if ast_util::is_local(did) {
154-
Some("../".repeat(loc.len()))
154+
Some(("../".repeat(loc.len())).to_strbuf())
155155
} else {
156156
match *cache.extern_locations.get(&did.krate) {
157-
render::Remote(ref s) => Some(s.clone()),
158-
render::Local => Some("../".repeat(loc.len())),
157+
render::Remote(ref s) => Some(s.to_strbuf()),
158+
render::Local => {
159+
Some(("../".repeat(loc.len())).to_strbuf())
160+
}
159161
render::Unknown => None,
160162
}
161163
}
@@ -169,8 +171,8 @@ fn resolved_path(w: &mut io::Writer, did: ast::DefId, p: &clean::Path,
169171
}
170172

171173
fn path(w: &mut io::Writer, path: &clean::Path, print_all: bool,
172-
root: |&render::Cache, &[~str]| -> Option<~str>,
173-
info: |&render::Cache| -> Option<(Vec<~str> , ItemType)>)
174+
root: |&render::Cache, &[StrBuf]| -> Option<StrBuf>,
175+
info: |&render::Cache| -> Option<(Vec<StrBuf> , ItemType)>)
174176
-> fmt::Result
175177
{
176178
// The generics will get written to both the title and link
@@ -206,10 +208,11 @@ fn path(w: &mut io::Writer, path: &clean::Path, print_all: bool,
206208
Some(root) => {
207209
let mut root = StrBuf::from_str(root);
208210
for seg in path.segments.slice_to(amt).iter() {
209-
if "super" == seg.name || "self" == seg.name {
211+
if "super" == seg.name.as_slice() ||
212+
"self" == seg.name.as_slice() {
210213
try!(write!(w, "{}::", seg.name));
211214
} else {
212-
root.push_str(seg.name);
215+
root.push_str(seg.name.as_slice());
213216
root.push_str("/");
214217
try!(write!(w, "<a class='mod'
215218
href='{}index.html'>{}</a>::",
@@ -229,21 +232,21 @@ fn path(w: &mut io::Writer, path: &clean::Path, print_all: bool,
229232
match info(&**cache) {
230233
// This is a documented path, link to it!
231234
Some((ref fqp, shortty)) if abs_root.is_some() => {
232-
let mut url = StrBuf::from_str(abs_root.unwrap());
235+
let mut url = StrBuf::from_str(abs_root.unwrap().as_slice());
233236
let to_link = fqp.slice_to(fqp.len() - 1);
234237
for component in to_link.iter() {
235-
url.push_str(*component);
238+
url.push_str(component.as_slice());
236239
url.push_str("/");
237240
}
238241
match shortty {
239242
item_type::Module => {
240-
url.push_str(*fqp.last().unwrap());
243+
url.push_str(fqp.last().unwrap().as_slice());
241244
url.push_str("/index.html");
242245
}
243246
_ => {
244247
url.push_str(shortty.to_static_str());
245248
url.push_str(".");
246-
url.push_str(*fqp.last().unwrap());
249+
url.push_str(fqp.last().unwrap().as_slice());
247250
url.push_str(".html");
248251
}
249252
}
@@ -352,16 +355,20 @@ impl fmt::Show for clean::Type {
352355
{arrow, select, yes{ -&gt; {ret}} other{}}",
353356
style = FnStyleSpace(decl.fn_style),
354357
lifetimes = if decl.lifetimes.len() == 0 {
355-
"".to_owned()
358+
"".to_strbuf()
356359
} else {
357-
format!("&lt;{:#}&gt;", decl.lifetimes)
360+
format_strbuf!("&lt;{:#}&gt;", decl.lifetimes)
358361
},
359362
args = decl.decl.inputs,
360363
bounds = if decl.bounds.len() == 0 {
361-
"".to_owned()
364+
"".to_strbuf()
362365
} else {
363-
let mut m = decl.bounds.iter().map(|s| s.to_str());
364-
": " + m.collect::<Vec<~str>>().connect(" + ")
366+
let mut m = decl.bounds
367+
.iter()
368+
.map(|s| s.to_str().to_strbuf());
369+
format_strbuf!(
370+
": {}",
371+
m.collect::<Vec<StrBuf>>().connect(" + "))
365372
},
366373
arrow = match decl.decl.output { clean::Unit => "no", _ => "yes" },
367374
ret = decl.decl.output)
@@ -370,9 +377,9 @@ impl fmt::Show for clean::Type {
370377
write!(f.buf, "{}{}fn{}{}",
371378
FnStyleSpace(decl.fn_style),
372379
match decl.abi.as_slice() {
373-
"" => " extern ".to_owned(),
374-
"\"Rust\"" => "".to_owned(),
375-
s => format!(" extern {} ", s)
380+
"" => " extern ".to_strbuf(),
381+
"\"Rust\"" => "".to_strbuf(),
382+
s => format_strbuf!(" extern {} ", s)
376383
},
377384
decl.generics,
378385
decl.decl)

src/librustdoc/html/highlight.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use html::escape::Escape;
2525
use t = syntax::parse::token;
2626

2727
/// Highlights some source code, returning the HTML output.
28-
pub fn highlight(src: &str, class: Option<&str>) -> ~str {
28+
pub fn highlight(src: &str, class: Option<&str>) -> StrBuf {
2929
let sess = parse::new_parse_sess();
3030
let fm = parse::string_to_filemap(&sess,
3131
src.to_strbuf(),
@@ -36,7 +36,7 @@ pub fn highlight(src: &str, class: Option<&str>) -> ~str {
3636
lexer::new_string_reader(&sess.span_diagnostic, fm),
3737
class,
3838
&mut out).unwrap();
39-
str::from_utf8_lossy(out.unwrap().as_slice()).into_owned()
39+
str::from_utf8_lossy(out.unwrap().as_slice()).to_strbuf()
4040
}
4141

4242
/// Exhausts the `lexer` writing the output into `out`.

src/librustdoc/html/layout.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ use std::io;
1313

1414
#[deriving(Clone)]
1515
pub struct Layout {
16-
pub logo: ~str,
17-
pub favicon: ~str,
18-
pub krate: ~str,
16+
pub logo: StrBuf,
17+
pub favicon: StrBuf,
18+
pub krate: StrBuf,
1919
}
2020

2121
pub struct Page<'a> {
@@ -119,9 +119,9 @@ r##"<!DOCTYPE html>
119119
content = *t,
120120
root_path = page.root_path,
121121
ty = page.ty,
122-
logo = nonestr(layout.logo),
122+
logo = nonestr(layout.logo.as_slice()),
123123
title = page.title,
124-
favicon = nonestr(layout.favicon),
124+
favicon = nonestr(layout.favicon.as_slice()),
125125
sidebar = *sidebar,
126126
krate = layout.krate,
127127
)

src/librustdoc/html/markdown.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ fn stripped_filtered_line<'a>(s: &'a str) -> Option<&'a str> {
139139
}
140140
}
141141

142-
local_data_key!(used_header_map: RefCell<HashMap<~str, uint>>)
142+
local_data_key!(used_header_map: RefCell<HashMap<StrBuf, uint>>)
143143

144144
pub fn render(w: &mut io::Writer, s: &str, print_toc: bool) -> fmt::Result {
145145
extern fn block(ob: *mut hoedown_buffer, text: *hoedown_buffer,
@@ -177,7 +177,8 @@ pub fn render(w: &mut io::Writer, s: &str, print_toc: bool) -> fmt::Result {
177177
};
178178

179179
if !rendered {
180-
let output = highlight::highlight(text, None).to_c_str();
180+
let output = highlight::highlight(text, None).as_slice()
181+
.to_c_str();
181182
output.with_ref(|r| {
182183
hoedown_buffer_puts(ob, r)
183184
})
@@ -201,16 +202,16 @@ pub fn render(w: &mut io::Writer, s: &str, print_toc: bool) -> fmt::Result {
201202
};
202203

203204
// Transform the contents of the header into a hyphenated string
204-
let id = s.words().map(|s| {
205+
let id = (s.words().map(|s| {
205206
match s.to_ascii_opt() {
206-
Some(s) => s.to_lower().into_str(),
207-
None => s.to_owned()
207+
Some(s) => s.to_lower().into_str().to_strbuf(),
208+
None => s.to_strbuf()
208209
}
209-
}).collect::<Vec<~str>>().connect("-");
210+
}).collect::<Vec<StrBuf>>().connect("-")).to_strbuf();
210211

211212
// This is a terrible hack working around how hoedown gives us rendered
212213
// html for text rather than the raw text.
213-
let id = id.replace("<code>", "").replace("</code>", "");
214+
let id = id.replace("<code>", "").replace("</code>", "").to_strbuf();
214215

215216
let opaque = opaque as *mut hoedown_html_renderer_state;
216217
let opaque = unsafe { &mut *((*opaque).opaque as *mut MyOpaque) };
@@ -219,13 +220,13 @@ pub fn render(w: &mut io::Writer, s: &str, print_toc: bool) -> fmt::Result {
219220
let map = used_header_map.get().unwrap();
220221
let id = match map.borrow_mut().find_mut(&id) {
221222
None => id,
222-
Some(a) => { *a += 1; format!("{}-{}", id, *a - 1) }
223+
Some(a) => { *a += 1; format_strbuf!("{}-{}", id, *a - 1) }
223224
};
224225
map.borrow_mut().insert(id.clone(), 1);
225226

226227
let sec = match opaque.toc_builder {
227228
Some(ref mut builder) => {
228-
builder.push(level as u32, s.clone(), id.clone())
229+
builder.push(level as u32, s.to_strbuf(), id.clone())
229230
}
230231
None => {""}
231232
};
@@ -298,7 +299,7 @@ pub fn find_testable_code(doc: &str, tests: &mut ::test::Collector) {
298299
stripped_filtered_line(l).unwrap_or(l)
299300
});
300301
let text = lines.collect::<Vec<&str>>().connect("\n");
301-
tests.add_test(text, should_fail, no_run, ignore);
302+
tests.add_test(text.to_strbuf(), should_fail, no_run, ignore);
302303
})
303304
}
304305
}

0 commit comments

Comments
 (0)