auto merge of #15493 : brson/rust/tostr, r=pcwalton
This updates https://github.com/rust-lang/rust/pull/15075. Rename `ToStr::to_str` to `ToString::to_string`. The naive renaming ends up with two `to_string` functions defined on strings in the prelude (the other defined via `collections::str::StrAllocating`). To remedy this I removed `StrAllocating::to_string`, making all conversions from `&str` to `String` go through `Show`. This has a measurable impact on the speed of this conversion, but the sense I get from others is that it's best to go ahead and unify `to_string` and address performance for all `to_string` conversions in `core::fmt`. `String::from_str(...)` still works as a manual fast-path. Note that the patch was done with a script, and ended up renaming a number of other `*_to_str` functions, particularly inside of rustc. All the ones I saw looked correct, and I didn't notice any additional API breakage. Closes #15046.
This commit is contained in:
commit
8bb34a3146
208 changed files with 1557 additions and 1390 deletions
|
@ -141,7 +141,7 @@ impl fmt::Show for Nonterminal {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn binop_to_str(o: BinOp) -> &'static str {
|
||||
pub fn binop_to_string(o: BinOp) -> &'static str {
|
||||
match o {
|
||||
PLUS => "+",
|
||||
MINUS => "-",
|
||||
|
@ -156,7 +156,7 @@ pub fn binop_to_str(o: BinOp) -> &'static str {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn to_str(t: &Token) -> String {
|
||||
pub fn to_string(t: &Token) -> String {
|
||||
match *t {
|
||||
EQ => "=".to_string(),
|
||||
LT => "<".to_string(),
|
||||
|
@ -169,9 +169,9 @@ pub fn to_str(t: &Token) -> String {
|
|||
TILDE => "~".to_string(),
|
||||
OROR => "||".to_string(),
|
||||
ANDAND => "&&".to_string(),
|
||||
BINOP(op) => binop_to_str(op).to_string(),
|
||||
BINOP(op) => binop_to_string(op).to_string(),
|
||||
BINOPEQ(op) => {
|
||||
let mut s = binop_to_str(op).to_string();
|
||||
let mut s = binop_to_string(op).to_string();
|
||||
s.push_str("=");
|
||||
s
|
||||
}
|
||||
|
@ -215,15 +215,15 @@ pub fn to_str(t: &Token) -> String {
|
|||
res.push_char('\'');
|
||||
res
|
||||
}
|
||||
LIT_INT(i, t) => ast_util::int_ty_to_str(t, Some(i)),
|
||||
LIT_UINT(u, t) => ast_util::uint_ty_to_str(t, Some(u)),
|
||||
LIT_INT_UNSUFFIXED(i) => { (i as u64).to_str() }
|
||||
LIT_INT(i, t) => ast_util::int_ty_to_string(t, Some(i)),
|
||||
LIT_UINT(u, t) => ast_util::uint_ty_to_string(t, Some(u)),
|
||||
LIT_INT_UNSUFFIXED(i) => { (i as u64).to_string() }
|
||||
LIT_FLOAT(s, t) => {
|
||||
let mut body = String::from_str(get_ident(s).get());
|
||||
if body.as_slice().ends_with(".") {
|
||||
body.push_char('0'); // `10.f` is not a float literal
|
||||
}
|
||||
body.push_str(ast_util::float_ty_to_str(t).as_slice());
|
||||
body.push_str(ast_util::float_ty_to_string(t).as_slice());
|
||||
body
|
||||
}
|
||||
LIT_FLOAT_UNSUFFIXED(s) => {
|
||||
|
@ -262,8 +262,8 @@ pub fn to_str(t: &Token) -> String {
|
|||
EOF => "<eof>".to_string(),
|
||||
INTERPOLATED(ref nt) => {
|
||||
match nt {
|
||||
&NtExpr(ref e) => ::print::pprust::expr_to_str(&**e),
|
||||
&NtMeta(ref e) => ::print::pprust::meta_item_to_str(&**e),
|
||||
&NtExpr(ref e) => ::print::pprust::expr_to_string(&**e),
|
||||
&NtMeta(ref e) => ::print::pprust::meta_item_to_string(&**e),
|
||||
_ => {
|
||||
let mut s = "an interpolated ".to_string();
|
||||
match *nt {
|
||||
|
@ -693,7 +693,7 @@ pub fn gensym_ident(s: &str) -> ast::Ident {
|
|||
}
|
||||
|
||||
// create a fresh name that maps to the same string as the old one.
|
||||
// note that this guarantees that str_ptr_eq(ident_to_str(src),interner_get(fresh_name(src)));
|
||||
// note that this guarantees that str_ptr_eq(ident_to_string(src),interner_get(fresh_name(src)));
|
||||
// that is, that the new name and the old one are connected to ptr_eq strings.
|
||||
pub fn fresh_name(src: &ast::Ident) -> Name {
|
||||
let interner = get_ident_interner();
|
||||
|
@ -702,7 +702,7 @@ pub fn fresh_name(src: &ast::Ident) -> Name {
|
|||
// good error messages and uses of struct names in ambiguous could-be-binding
|
||||
// locations. Also definitely destroys the guarantee given above about ptr_eq.
|
||||
/*let num = rand::task_rng().gen_uint_range(0,0xffff);
|
||||
gensym(format!("{}_{}",ident_to_str(src),num))*/
|
||||
gensym(format!("{}_{}",ident_to_string(src),num))*/
|
||||
}
|
||||
|
||||
// create a fresh mark.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue