Skip to content

Commit 330378d

Browse files
committed
auto merge of #7996 : erickt/rust/cleanup-strs, r=erickt
This is a cleanup pull request that does: * removes `os::as_c_charp` * moves `str::as_buf` and `str::as_c_str` into `StrSlice` * converts some functions from `StrSlice::as_buf` to `StrSlice::as_c_str` * renames `StrSlice::as_buf` to `StrSlice::as_imm_buf` (and adds `StrSlice::as_mut_buf` to match `vec.rs`. * renames `UniqueStr::as_bytes_with_null_consume` to `UniqueStr::to_bytes` * and other misc cleanups and minor optimizations
2 parents 766eb95 + 9a95080 commit 330378d

39 files changed

+380
-466
lines changed

src/libextra/future.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ mod test {
194194
195195
#[test]
196196
fn test_interface_unwrap() {
197-
let mut f = from_value(~"fail");
197+
let f = from_value(~"fail");
198198
assert_eq!(f.unwrap(), ~"fail");
199199
}
200200

src/libextra/getopts.rs

+21-21
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ pub fn opt_default(mm: &Matches, nm: &str, def: &str) -> Option<~str> {
457457
let vals = opt_vals(mm, nm);
458458
if vals.is_empty() { return None::<~str>; }
459459
return match vals[0] { Val(ref s) => Some::<~str>((*s).clone()),
460-
_ => Some::<~str>(str::to_owned(def)) }
460+
_ => Some::<~str>(def.to_owned()) }
461461
}
462462

463463
#[deriving(Eq)]
@@ -497,10 +497,10 @@ pub mod groups {
497497
desc: &str, hint: &str) -> OptGroup {
498498
let len = short_name.len();
499499
assert!(len == 1 || len == 0);
500-
return OptGroup { short_name: str::to_owned(short_name),
501-
long_name: str::to_owned(long_name),
502-
hint: str::to_owned(hint),
503-
desc: str::to_owned(desc),
500+
return OptGroup { short_name: short_name.to_owned(),
501+
long_name: long_name.to_owned(),
502+
hint: hint.to_owned(),
503+
desc: desc.to_owned(),
504504
hasarg: Yes,
505505
occur: Req};
506506
}
@@ -510,10 +510,10 @@ pub mod groups {
510510
desc: &str, hint: &str) -> OptGroup {
511511
let len = short_name.len();
512512
assert!(len == 1 || len == 0);
513-
return OptGroup {short_name: str::to_owned(short_name),
514-
long_name: str::to_owned(long_name),
515-
hint: str::to_owned(hint),
516-
desc: str::to_owned(desc),
513+
return OptGroup {short_name: short_name.to_owned(),
514+
long_name: long_name.to_owned(),
515+
hint: hint.to_owned(),
516+
desc: desc.to_owned(),
517517
hasarg: Yes,
518518
occur: Optional};
519519
}
@@ -523,10 +523,10 @@ pub mod groups {
523523
desc: &str) -> OptGroup {
524524
let len = short_name.len();
525525
assert!(len == 1 || len == 0);
526-
return OptGroup {short_name: str::to_owned(short_name),
527-
long_name: str::to_owned(long_name),
526+
return OptGroup {short_name: short_name.to_owned(),
527+
long_name: long_name.to_owned(),
528528
hint: ~"",
529-
desc: str::to_owned(desc),
529+
desc: desc.to_owned(),
530530
hasarg: No,
531531
occur: Optional};
532532
}
@@ -536,10 +536,10 @@ pub mod groups {
536536
desc: &str, hint: &str) -> OptGroup {
537537
let len = short_name.len();
538538
assert!(len == 1 || len == 0);
539-
return OptGroup {short_name: str::to_owned(short_name),
540-
long_name: str::to_owned(long_name),
541-
hint: str::to_owned(hint),
542-
desc: str::to_owned(desc),
539+
return OptGroup {short_name: short_name.to_owned(),
540+
long_name: long_name.to_owned(),
541+
hint: hint.to_owned(),
542+
desc: desc.to_owned(),
543543
hasarg: Maybe,
544544
occur: Optional};
545545
}
@@ -552,10 +552,10 @@ pub mod groups {
552552
desc: &str, hint: &str) -> OptGroup {
553553
let len = short_name.len();
554554
assert!(len == 1 || len == 0);
555-
return OptGroup {short_name: str::to_owned(short_name),
556-
long_name: str::to_owned(long_name),
557-
hint: str::to_owned(hint),
558-
desc: str::to_owned(desc),
555+
return OptGroup {short_name: short_name.to_owned(),
556+
long_name: long_name.to_owned(),
557+
hint: hint.to_owned(),
558+
desc: desc.to_owned(),
559559
hasarg: Yes,
560560
occur: Multi};
561561
}
@@ -678,7 +678,7 @@ pub mod groups {
678678
row
679679
});
680680

681-
return str::to_owned(brief) +
681+
return brief.to_owned() +
682682
"\n\nOptions:\n" +
683683
rows.collect::<~[~str]>().connect("\n") +
684684
"\n\n";

src/libextra/rl.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ pub mod rustrt {
3232

3333
/// Add a line to history
3434
pub unsafe fn add_history(line: &str) -> bool {
35-
do str::as_c_str(line) |buf| {
35+
do line.as_c_str |buf| {
3636
rustrt::linenoiseHistoryAdd(buf) == 1 as c_int
3737
}
3838
}
@@ -44,21 +44,21 @@ pub unsafe fn set_history_max_len(len: int) -> bool {
4444

4545
/// Save line history to a file
4646
pub unsafe fn save_history(file: &str) -> bool {
47-
do str::as_c_str(file) |buf| {
47+
do file.as_c_str |buf| {
4848
rustrt::linenoiseHistorySave(buf) == 1 as c_int
4949
}
5050
}
5151

5252
/// Load line history from a file
5353
pub unsafe fn load_history(file: &str) -> bool {
54-
do str::as_c_str(file) |buf| {
54+
do file.as_c_str |buf| {
5555
rustrt::linenoiseHistoryLoad(buf) == 1 as c_int
5656
}
5757
}
5858

5959
/// Print out a prompt and then wait for input and return it
6060
pub unsafe fn read(prompt: &str) -> Option<~str> {
61-
do str::as_c_str(prompt) |buf| {
61+
do prompt.as_c_str |buf| {
6262
let line = rustrt::linenoise(buf);
6363

6464
if line.is_null() { None }
@@ -80,7 +80,7 @@ pub unsafe fn complete(cb: CompletionCb) {
8080

8181
unsafe {
8282
do cb(str::raw::from_c_str(line)) |suggestion| {
83-
do str::as_c_str(suggestion) |buf| {
83+
do suggestion.as_c_str |buf| {
8484
rustrt::linenoiseAddCompletion(completions, buf);
8585
}
8686
}

src/libextra/terminfo/parm.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ priv fn format(val: Param, op: FormatOp, flags: Flags) -> Result<~[u8],~str> {
545545
String(s) => {
546546
match op {
547547
FormatString => {
548-
let mut s = s.as_bytes_with_null_consume();
548+
let mut s = s.to_bytes_with_null();
549549
s.pop(); // remove the null
550550
if flags.precision > 0 && flags.precision < s.len() {
551551
s.truncate(flags.precision);

src/libextra/time.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1027,7 +1027,7 @@ mod tests {
10271027
10281028
fn test(s: &str, format: &str) -> bool {
10291029
match strptime(s, format) {
1030-
Ok(ref tm) => tm.strftime(format) == str::to_owned(s),
1030+
Ok(ref tm) => tm.strftime(format) == s.to_owned(),
10311031
Err(e) => fail!(e)
10321032
}
10331033
}

src/librustc/back/link.rs

+17-15
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@ pub fn WriteOutputFile(sess: Session,
7676
OptLevel: c_int,
7777
EnableSegmentedStacks: bool) {
7878
unsafe {
79-
do str::as_c_str(Triple) |Triple| {
80-
do str::as_c_str(Feature) |Feature| {
81-
do str::as_c_str(Output) |Output| {
79+
do Triple.as_c_str |Triple| {
80+
do Feature.as_c_str |Feature| {
81+
do Output.as_c_str |Output| {
8282
let result = llvm::LLVMRustWriteOutputFile(
8383
PM,
8484
M,
@@ -263,16 +263,16 @@ pub mod write {
263263
output_type_bitcode => {
264264
if opts.optimize != session::No {
265265
let filename = output.with_filetype("no-opt.bc");
266-
str::as_c_str(filename.to_str(), |buf| {
267-
llvm::LLVMWriteBitcodeToFile(llmod, buf)
268-
});
266+
do filename.to_str().as_c_str |buf| {
267+
llvm::LLVMWriteBitcodeToFile(llmod, buf);
268+
}
269269
}
270270
}
271271
_ => {
272272
let filename = output.with_filetype("bc");
273-
str::as_c_str(filename.to_str(), |buf| {
274-
llvm::LLVMWriteBitcodeToFile(llmod, buf)
275-
});
273+
do filename.to_str().as_c_str |buf| {
274+
llvm::LLVMWriteBitcodeToFile(llmod, buf);
275+
}
276276
}
277277
}
278278
}
@@ -333,9 +333,9 @@ pub mod write {
333333
// Always output the bitcode file with --save-temps
334334

335335
let filename = output.with_filetype("opt.bc");
336-
str::as_c_str(filename.to_str(), |buf| {
336+
do filename.to_str().as_c_str |buf| {
337337
llvm::LLVMWriteBitcodeToFile(llmod, buf)
338-
});
338+
};
339339
// Save the assembly file if -S is used
340340
if output_type == output_type_assembly {
341341
WriteOutputFile(
@@ -391,13 +391,15 @@ pub mod write {
391391

392392
if output_type == output_type_llvm_assembly {
393393
// Given options "-S --emit-llvm": output LLVM assembly
394-
str::as_c_str(output.to_str(), |buf_o| {
395-
llvm::LLVMRustAddPrintModulePass(pm.llpm, llmod, buf_o)});
394+
do output.to_str().as_c_str |buf_o| {
395+
llvm::LLVMRustAddPrintModulePass(pm.llpm, llmod, buf_o);
396+
}
396397
} else {
397398
// If only a bitcode file is asked for by using the
398399
// '--emit-llvm' flag, then output it here
399-
str::as_c_str(output.to_str(),
400-
|buf| llvm::LLVMWriteBitcodeToFile(llmod, buf) );
400+
do output.to_str().as_c_str |buf| {
401+
llvm::LLVMWriteBitcodeToFile(llmod, buf);
402+
}
401403
}
402404

403405
llvm::LLVMDisposeModule(llmod);

src/librustc/back/passes.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use std::str;
1211
use std::io;
1312

1413
use driver::session::{OptLevel, No, Less, Aggressive};
@@ -174,7 +173,7 @@ pub fn populate_pass_manager(sess: Session, pm: &mut PassManager, pass_list:&[~s
174173
}
175174

176175
pub fn create_pass(name:&str) -> Option<PassRef> {
177-
do str::as_c_str(name) |s| {
176+
do name.as_c_str |s| {
178177
unsafe {
179178
let p = llvm::LLVMCreatePass(s);
180179
if p.is_null() {

src/librustc/lib/llvm.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
use std::hashmap::HashMap;
1313
use std::libc::{c_uint, c_ushort};
1414
use std::option;
15-
use std::str;
1615

1716
use middle::trans::type_::Type;
1817

@@ -2287,10 +2286,9 @@ pub struct TargetData {
22872286
}
22882287

22892288
pub fn mk_target_data(string_rep: &str) -> TargetData {
2290-
let lltd =
2291-
str::as_c_str(string_rep, |buf| unsafe {
2292-
llvm::LLVMCreateTargetData(buf)
2293-
});
2289+
let lltd = do string_rep.as_c_str |buf| {
2290+
unsafe { llvm::LLVMCreateTargetData(buf) }
2291+
};
22942292

22952293
TargetData {
22962294
lltd: lltd,

src/librustc/metadata/filesearch.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
use std::option;
1313
use std::os;
1414
use std::result;
15-
use std::str;
1615

1716
// A module for searching for libraries
1817
// FIXME (#2658): I'm not happy how this module turned out. Should
@@ -83,7 +82,7 @@ pub fn mk_filesearch(maybe_sysroot: &Option<@Path>,
8382
@FileSearchImpl {
8483
sysroot: sysroot,
8584
addl_lib_search_paths: addl_lib_search_paths,
86-
target_triple: str::to_owned(target_triple)
85+
target_triple: target_triple.to_owned()
8786
} as @FileSearch
8887
}
8988

@@ -110,7 +109,7 @@ pub fn search<T>(filesearch: @FileSearch, pick: pick<T>) -> Option<T> {
110109

111110
pub fn relative_target_lib_path(target_triple: &str) -> Path {
112111
Path(libdir()).push_many([~"rustc",
113-
str::to_owned(target_triple),
112+
target_triple.to_owned(),
114113
libdir()])
115114
}
116115

src/librustc/metadata/loader.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ fn libname(cx: &Context) -> (~str, ~str) {
8080
os_freebsd => (freebsd::DLL_PREFIX, freebsd::DLL_SUFFIX),
8181
};
8282

83-
(str::to_owned(dll_prefix), str::to_owned(dll_suffix))
83+
(dll_prefix.to_owned(), dll_suffix.to_owned())
8484
}
8585

8686
fn find_library_crate_aux(
@@ -186,9 +186,9 @@ pub fn metadata_matches(extern_metas: &[@ast::MetaItem],
186186
fn get_metadata_section(os: os,
187187
filename: &Path) -> Option<@~[u8]> {
188188
unsafe {
189-
let mb = str::as_c_str(filename.to_str(), |buf| {
189+
let mb = do filename.to_str().as_c_str |buf| {
190190
llvm::LLVMRustCreateMemoryBufferWithContentsOfFile(buf)
191-
});
191+
};
192192
if mb as int == 0 { return option::None::<@~[u8]>; }
193193
let of = match mk_object_file(mb) {
194194
option::Some(of) => of,

src/librustc/middle/trans/asm.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ use middle::ty;
2121

2222
use middle::trans::type_::Type;
2323

24-
use std::str;
2524
use syntax::ast;
2625

2726
// Take an inline assembly expression and splat it out via LLVM
@@ -123,8 +122,8 @@ pub fn trans_inline_asm(bcx: @mut Block, ia: &ast::inline_asm) -> @mut Block {
123122
ast::asm_intel => lib::llvm::AD_Intel
124123
};
125124

126-
let r = do str::as_c_str(ia.asm) |a| {
127-
do str::as_c_str(constraints) |c| {
125+
let r = do ia.asm.as_c_str |a| {
126+
do constraints.as_c_str |c| {
128127
InlineAsmCall(bcx, a, c, inputs, output, ia.volatile, ia.alignstack, dialect)
129128
}
130129
};

0 commit comments

Comments
 (0)