Skip to content

Commit b8418da

Browse files
committed
port qquote to use dvec
1 parent b4be2c6 commit b8418da

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

src/librustsyntax/ext/qquote.rs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,17 @@ import ext::base::*;
66
import ext::build::*;
77
import parse::parser;
88
import parse::parser::parse_from_source_str;
9+
import dvec::{dvec, extensions};
910

1011
import print::*;
1112
import io::*;
1213

1314
import codemap::span;
1415

1516
type aq_ctxt = @{lo: uint,
16-
mut gather: [{lo: uint, hi: uint,
17-
e: @ast::expr,
18-
constr: str}]};
17+
gather: dvec<{lo: uint, hi: uint,
18+
e: @ast::expr,
19+
constr: str}>};
1920
enum fragment {
2021
from_expr(@ast::expr),
2122
from_ty(@ast::ty)
@@ -101,20 +102,22 @@ fn gather_anti_quotes<N: qq_helper>(lo: uint, node: N) -> aq_ctxt
101102
visit_ty: {|node, &&cx, v|
102103
visit_aq(node, "from_ty", cx, v)}
103104
with *default_visitor()};
104-
let cx = @{lo:lo, mut gather: []};
105+
let cx = @{lo:lo, gather: dvec()};
105106
node.visit(cx, mk_vt(v));
106107
// FIXME: Maybe this is an overkill (merge_sort), it might be better
107108
// to just keep the gather array in sorted order ... (Issue #2250)
108-
cx.gather = std::sort::merge_sort({|a,b| a.lo < b.lo}, copy cx.gather);
109+
cx.gather.swap { |v|
110+
vec::to_mut(std::sort::merge_sort({|a,b| a.lo < b.lo}, v))
111+
};
109112
ret cx;
110113
}
111114

112115
fn visit_aq<T:qq_helper>(node: T, constr: str, &&cx: aq_ctxt, v: vt<aq_ctxt>)
113116
{
114117
alt (node.extract_mac()) {
115118
some(mac_aq(sp, e)) {
116-
cx.gather += [{lo: sp.lo - cx.lo, hi: sp.hi - cx.lo,
117-
e: e, constr: constr}];
119+
cx.gather.push({lo: sp.lo - cx.lo, hi: sp.hi - cx.lo,
120+
e: e, constr: constr});
118121
}
119122
_ {node.visit(cx, v);}
120123
}
@@ -196,7 +199,7 @@ fn finish<T: qq_helper>
196199
let qcx = gather_anti_quotes(sp.lo, node);
197200
let cx = qcx;
198201

199-
uint::range(1u, vec::len(cx.gather)) {|i|
202+
uint::range(1u, cx.gather.len()) {|i|
200203
assert cx.gather[i-1u].lo < cx.gather[i].lo;
201204
// ^^ check that the vector is sorted
202205
assert cx.gather[i-1u].hi <= cx.gather[i].lo;
@@ -207,7 +210,7 @@ fn finish<T: qq_helper>
207210
enum state {active, skip(uint), blank};
208211
let mut state = active;
209212
let mut i = 0u, j = 0u;
210-
let g_len = vec::len(cx.gather);
213+
let g_len = cx.gather.len();
211214
str::chars_iter(*str) {|ch|
212215
if (j < g_len && i == cx.gather[j].lo) {
213216
assert ch == '$';
@@ -261,7 +264,7 @@ fn finish<T: qq_helper>
261264
rcall = mk_call(cx,sp,
262265
["syntax", "ext", "qquote", "replace"],
263266
[pcall,
264-
mk_vec_e(cx,sp, vec::map(gather) {|g|
267+
mk_vec_e(cx,sp, qcx.gather.map_to_vec {|g|
265268
mk_call(cx,sp,
266269
["syntax", "ext", "qquote", g.constr],
267270
[g.e])}),

0 commit comments

Comments
 (0)