diff options
| author | bors <bors@rust-lang.org> | 2014-04-10 21:01:41 -0700 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2014-04-10 21:01:41 -0700 |
| commit | cea8def62068b405495ecd1810124ebc88b4f90b (patch) | |
| tree | 65d5755bd532a9213799c52572db6d6683d5e942 /src/libsyntax/ext | |
| parent | 0156af156d70efd5a3c96d0c5b8fc9bec39a7ae5 (diff) | |
| parent | def90f43e2df9968cda730a2a30cb7ccb9513002 (diff) | |
| download | rust-cea8def62068b405495ecd1810124ebc88b4f90b.tar.gz rust-cea8def62068b405495ecd1810124ebc88b4f90b.zip | |
auto merge of #13440 : huonw/rust/strbuf, r=alexcrichton
libstd: Implement `StrBuf`, a new string buffer type like `Vec`, and port all code over to use it. Rebased & tests-fixed version of https://github.com/mozilla/rust/pull/13269
Diffstat (limited to 'src/libsyntax/ext')
| -rw-r--r-- | src/libsyntax/ext/concat.rs | 11 | ||||
| -rw-r--r-- | src/libsyntax/ext/concat_idents.rs | 6 | ||||
| -rw-r--r-- | src/libsyntax/ext/deriving/show.rs | 6 |
3 files changed, 14 insertions, 9 deletions
diff --git a/src/libsyntax/ext/concat.rs b/src/libsyntax/ext/concat.rs index e638291ecfa..1db65e3b9e4 100644 --- a/src/libsyntax/ext/concat.rs +++ b/src/libsyntax/ext/concat.rs @@ -8,14 +8,15 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use std::char; - use ast; use codemap; use ext::base; use ext::build::AstBuilder; use parse::token; +use std::char; +use std::strbuf::StrBuf; + pub fn expand_syntax_ext(cx: &mut base::ExtCtxt, sp: codemap::Span, tts: &[ast::TokenTree]) -> base::MacResult { @@ -23,7 +24,7 @@ pub fn expand_syntax_ext(cx: &mut base::ExtCtxt, Some(e) => e, None => return base::MacResult::dummy_expr(sp) }; - let mut accumulator = ~""; + let mut accumulator = StrBuf::new(); for e in es.move_iter() { match e.node { ast::ExprLit(lit) => { @@ -56,5 +57,7 @@ pub fn expand_syntax_ext(cx: &mut base::ExtCtxt, } } } - base::MRExpr(cx.expr_str(sp, token::intern_and_get_ident(accumulator))) + base::MRExpr(cx.expr_str( + sp, + token::intern_and_get_ident(accumulator.into_owned()))) } diff --git a/src/libsyntax/ext/concat_idents.rs b/src/libsyntax/ext/concat_idents.rs index 8441fa719ea..a5faa693982 100644 --- a/src/libsyntax/ext/concat_idents.rs +++ b/src/libsyntax/ext/concat_idents.rs @@ -16,9 +16,11 @@ use owned_slice::OwnedSlice; use parse::token; use parse::token::{str_to_ident}; +use std::strbuf::StrBuf; + pub fn expand_syntax_ext(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) -> base::MacResult { - let mut res_str = ~""; + let mut res_str = StrBuf::new(); for (i, e) in tts.iter().enumerate() { if i & 1 == 1 { match *e { @@ -40,7 +42,7 @@ pub fn expand_syntax_ext(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) } } } - let res = str_to_ident(res_str); + let res = str_to_ident(res_str.into_owned()); let e = @ast::Expr { id: ast::DUMMY_NODE_ID, diff --git a/src/libsyntax/ext/deriving/show.rs b/src/libsyntax/ext/deriving/show.rs index 1c80fb9ced2..067958e4bde 100644 --- a/src/libsyntax/ext/deriving/show.rs +++ b/src/libsyntax/ext/deriving/show.rs @@ -15,10 +15,10 @@ use ext::format; use ext::base::ExtCtxt; use ext::build::AstBuilder; use ext::deriving::generic::*; - use parse::token; use collections::HashMap; +use std::strbuf::StrBuf; pub fn expand_deriving_show(cx: &mut ExtCtxt, span: Span, @@ -68,7 +68,7 @@ fn show_substructure(cx: &mut ExtCtxt, span: Span, } }; - let mut format_string = token::get_ident(name).get().to_owned(); + let mut format_string = StrBuf::from_str(token::get_ident(name).get()); // the internal fields we're actually formatting let mut exprs = Vec::new(); @@ -129,7 +129,7 @@ fn show_substructure(cx: &mut ExtCtxt, span: Span, let write_call = cx.expr_call_global(span, std_write, vec!(buf, cx.expr_ident(span, args))); let format_closure = cx.lambda_expr(span, vec!(args), write_call); - let s = token::intern_and_get_ident(format_string); + let s = token::intern_and_get_ident(format_string.as_slice()); let format_string = cx.expr_str(span, s); // phew, not our responsibility any more! |
