Skip to content

Commit 9b9cf98

Browse files
committed
auto merge of #10701 : huonw/rust/rm-from_utf8, r=brson
This function had type &[u8] -> ~str, i.e. it allocates a string internally, even though the non-allocating version that take &[u8] -> &str and ~[u8] -> ~str are all that is necessary in most circumstances.
2 parents 5fa6bd5 + b0426ed commit 9b9cf98

36 files changed

+122
-226
lines changed

src/compiletest/procsrv.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,12 @@ pub fn run(lib_path: &str,
6060
for input in input.iter() {
6161
process.input().write(input.as_bytes());
6262
}
63-
let output = process.finish_with_output();
63+
let run::ProcessOutput { status, output, error } = process.finish_with_output();
6464

6565
Result {
66-
status: output.status,
67-
out: str::from_utf8(output.output),
68-
err: str::from_utf8(output.error)
66+
status: status,
67+
out: str::from_utf8_owned(output),
68+
err: str::from_utf8_owned(error)
6969
}
7070
}
7171

@@ -90,4 +90,3 @@ pub fn run_background(lib_path: &str,
9090

9191
return process;
9292
}
93-

src/compiletest/runtest.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ fn run_debuginfo_test(config: &config, props: &TestProps, testfile: &Path) {
298298

299299
let adb_arg = format!("export LD_LIBRARY_PATH={}; gdbserver :5039 {}/{}",
300300
config.adb_test_dir.clone(), config.adb_test_dir.clone(),
301-
str::from_utf8(exe_file.filename().unwrap())).clone();
301+
str::from_utf8(exe_file.filename().unwrap()));
302302

303303
let mut process = procsrv::run_background("", config.adb_path.clone(),
304304
[~"shell",adb_arg.clone()],~[(~"",~"")], Some(~""));
@@ -1151,4 +1151,3 @@ fn run_codegen_test(config: &config, props: &TestProps,
11511151
(base_lines as f64) / (clang_lines as f64),
11521152
0.001);
11531153
}
1154-

src/libextra/base64.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ impl<'self> FromBase64 for &'self str {
162162
* Convert any base64 encoded string (literal, `@`, `&`, or `~`)
163163
* to the byte values it encodes.
164164
*
165-
* You can use the `from_utf8` function in `std::str`
165+
* You can use the `from_utf8_owned` function in `std::str`
166166
* to turn a `[u8]` into a string with characters corresponding to those
167167
* values.
168168
*
@@ -180,7 +180,7 @@ impl<'self> FromBase64 for &'self str {
180180
* println!("base64 output: {}", hello_str);
181181
* let res = hello_str.from_base64();
182182
* if res.is_ok() {
183-
* let optBytes = str::from_utf8_opt(res.unwrap());
183+
* let optBytes = str::from_utf8_owned_opt(res.unwrap());
184184
* if optBytes.is_some() {
185185
* println!("decoded from base64: {}", optBytes.unwrap());
186186
* }

src/libextra/ebml.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ impl Doc {
4141
}
4242

4343
pub fn as_str_slice<'a>(&'a self) -> &'a str {
44-
str::from_utf8_slice(self.data.slice(self.start, self.end))
44+
str::from_utf8(self.data.slice(self.start, self.end))
4545
}
4646

4747
pub fn as_str(&self) -> ~str {

src/libextra/hex.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ impl<'self> FromHex for &'self str {
6262
* Convert any hexadecimal encoded string (literal, `@`, `&`, or `~`)
6363
* to the byte values it encodes.
6464
*
65-
* You can use the `from_utf8` function in `std::str`
65+
* You can use the `from_utf8_owned` function in `std::str`
6666
* to turn a `[u8]` into a string with characters corresponding to those
6767
* values.
6868
*
@@ -80,7 +80,7 @@ impl<'self> FromHex for &'self str {
8080
* println!("{}", hello_str);
8181
* let bytes = hello_str.from_hex().unwrap();
8282
* println!("{:?}", bytes);
83-
* let result_str = str::from_utf8(bytes);
83+
* let result_str = str::from_utf8_owned(bytes);
8484
* println!("{}", result_str);
8585
* }
8686
* ```

src/libextra/terminfo/parser/compiled.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,9 @@ pub fn parse(file: &mut io::Reader,
215215
return Err(~"incompatible file: more string offsets than expected");
216216
}
217217

218-
let names_str = str::from_utf8(file.read_bytes(names_bytes as uint - 1)); // don't read NUL
218+
// don't read NUL
219+
let names_str = str::from_utf8_owned(file.read_bytes(names_bytes as uint - 1));
220+
219221
let term_names: ~[~str] = names_str.split('|').map(|s| s.to_owned()).collect();
220222

221223
file.read_byte(); // consume NUL

src/libextra/uuid.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ impl Uuid {
310310
s[i*2+0] = digit[0];
311311
s[i*2+1] = digit[1];
312312
}
313-
str::from_utf8(s)
313+
str::from_utf8_owned(s)
314314
}
315315

316316
/// Returns a string of hexadecimal digits, separated into groups with a hypen

src/libextra/workcache.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ fn json_encode<'self, T:Encodable<json::Encoder<'self>>>(t: &T) -> ~str {
260260
let mut writer = MemWriter::new();
261261
let mut encoder = json::Encoder::init(&mut writer as &mut io::Writer);
262262
t.encode(&mut encoder);
263-
str::from_utf8(writer.inner_ref().as_slice())
263+
str::from_utf8_owned(writer.inner())
264264
}
265265

266266
// FIXME(#5121)

src/librustc/back/link.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ pub mod write {
368368
if !prog.status.success() {
369369
sess.err(format!("linking with `{}` failed: {}", cc, prog.status));
370370
sess.note(format!("{} arguments: '{}'", cc, args.connect("' '")));
371-
sess.note(str::from_utf8(prog.error + prog.output));
371+
sess.note(str::from_utf8_owned(prog.error + prog.output));
372372
sess.abort_if_errors();
373373
}
374374
}
@@ -1079,7 +1079,7 @@ fn link_natively(sess: Session, dylib: bool, obj_filename: &Path,
10791079
if !prog.status.success() {
10801080
sess.err(format!("linking with `{}` failed: {}", cc_prog, prog.status));
10811081
sess.note(format!("{} arguments: '{}'", cc_prog, cc_args.connect("' '")));
1082-
sess.note(str::from_utf8(prog.error + prog.output));
1082+
sess.note(str::from_utf8_owned(prog.error + prog.output));
10831083
sess.abort_if_errors();
10841084
}
10851085

src/librustc/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ Available lint options:
166166
max_key = num::max(name.len(), max_key);
167167
}
168168
fn padded(max: uint, s: &str) -> ~str {
169-
str::from_utf8(vec::from_elem(max - s.len(), ' ' as u8)) + s
169+
" ".repeat(max - s.len()) + s
170170
}
171171
println("\nAvailable lint checks:\n");
172172
println!(" {} {:7.7s} {}",
@@ -246,7 +246,7 @@ pub fn run_compiler(args: &[~str], demitter: @diagnostic::Emitter) {
246246
1u => {
247247
let ifile = matches.free[0].as_slice();
248248
if "-" == ifile {
249-
let src = str::from_utf8(io::stdin().read_to_end());
249+
let src = str::from_utf8_owned(io::stdin().read_to_end());
250250
str_input(src.to_managed())
251251
} else {
252252
file_input(Path::init(ifile))

0 commit comments

Comments
 (0)