Skip to content

Commit 7e9f3ea

Browse files
committed
auto merge of #13863 : huonw/rust/re-tweaks, r=pcwalton
Mostly code style e.g. avoiding `~` and using `for` + iterators.
2 parents ad37c0b + 33f98ad commit 7e9f3ea

File tree

7 files changed

+101
-117
lines changed

7 files changed

+101
-117
lines changed

src/libregex/compile.rs

+25-26
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
#![allow(visible_private_types)]
1414

1515
use std::cmp;
16-
use std::iter;
1716
use parse;
1817
use parse::{
1918
Flags, FLAG_EMPTY,
@@ -89,7 +88,7 @@ pub struct Program {
8988

9089
impl Program {
9190
/// Compiles a Regex given its AST.
92-
pub fn new(ast: ~parse::Ast) -> (Program, ~[Option<~str>]) {
91+
pub fn new(ast: parse::Ast) -> (Program, Vec<Option<~str>>) {
9392
let mut c = Compiler {
9493
insts: Vec::with_capacity(100),
9594
names: Vec::with_capacity(10),
@@ -104,16 +103,16 @@ impl Program {
104103
// This is a bit hacky since we have to skip over the initial
105104
// 'Save' instruction.
106105
let mut pre = StrBuf::with_capacity(5);
107-
for i in iter::range(1, c.insts.len()) {
108-
match *c.insts.get(i) {
106+
for inst in c.insts.slice_from(1).iter() {
107+
match *inst {
109108
OneChar(c, FLAG_EMPTY) => pre.push_char(c),
110109
_ => break
111110
}
112111
}
113112

114-
let names = c.names.as_slice().into_owned();
113+
let Compiler { insts, names } = c;
115114
let prog = Program {
116-
insts: c.insts,
115+
insts: insts,
117116
prefix: pre.into_owned(),
118117
};
119118
(prog, names)
@@ -144,48 +143,48 @@ struct Compiler<'r> {
144143
// The only tricky thing here is patching jump/split instructions to point to
145144
// the right instruction.
146145
impl<'r> Compiler<'r> {
147-
fn compile(&mut self, ast: ~parse::Ast) {
146+
fn compile(&mut self, ast: parse::Ast) {
148147
match ast {
149-
~Nothing => {},
150-
~Literal(c, flags) => self.push(OneChar(c, flags)),
151-
~Dot(nl) => self.push(Any(nl)),
152-
~Class(ranges, flags) =>
148+
Nothing => {},
149+
Literal(c, flags) => self.push(OneChar(c, flags)),
150+
Dot(nl) => self.push(Any(nl)),
151+
Class(ranges, flags) =>
153152
self.push(CharClass(ranges, flags)),
154-
~Begin(flags) => self.push(EmptyBegin(flags)),
155-
~End(flags) => self.push(EmptyEnd(flags)),
156-
~WordBoundary(flags) => self.push(EmptyWordBoundary(flags)),
157-
~Capture(cap, name, x) => {
153+
Begin(flags) => self.push(EmptyBegin(flags)),
154+
End(flags) => self.push(EmptyEnd(flags)),
155+
WordBoundary(flags) => self.push(EmptyWordBoundary(flags)),
156+
Capture(cap, name, x) => {
158157
let len = self.names.len();
159158
if cap >= len {
160159
self.names.grow(10 + cap - len, &None)
161160
}
162161
*self.names.get_mut(cap) = name;
163162

164163
self.push(Save(2 * cap));
165-
self.compile(x);
164+
self.compile(*x);
166165
self.push(Save(2 * cap + 1));
167166
}
168-
~Cat(xs) => {
167+
Cat(xs) => {
169168
for x in xs.move_iter() {
170169
self.compile(x)
171170
}
172171
}
173-
~Alt(x, y) => {
172+
Alt(x, y) => {
174173
let split = self.empty_split(); // push: split 0, 0
175174
let j1 = self.insts.len();
176-
self.compile(x); // push: insts for x
175+
self.compile(*x); // push: insts for x
177176
let jmp = self.empty_jump(); // push: jmp 0
178177
let j2 = self.insts.len();
179-
self.compile(y); // push: insts for y
178+
self.compile(*y); // push: insts for y
180179
let j3 = self.insts.len();
181180

182181
self.set_split(split, j1, j2); // split 0, 0 -> split j1, j2
183182
self.set_jump(jmp, j3); // jmp 0 -> jmp j3
184183
}
185-
~Rep(x, ZeroOne, g) => {
184+
Rep(x, ZeroOne, g) => {
186185
let split = self.empty_split();
187186
let j1 = self.insts.len();
188-
self.compile(x);
187+
self.compile(*x);
189188
let j2 = self.insts.len();
190189

191190
if g.is_greedy() {
@@ -194,11 +193,11 @@ impl<'r> Compiler<'r> {
194193
self.set_split(split, j2, j1);
195194
}
196195
}
197-
~Rep(x, ZeroMore, g) => {
196+
Rep(x, ZeroMore, g) => {
198197
let j1 = self.insts.len();
199198
let split = self.empty_split();
200199
let j2 = self.insts.len();
201-
self.compile(x);
200+
self.compile(*x);
202201
let jmp = self.empty_jump();
203202
let j3 = self.insts.len();
204203

@@ -209,9 +208,9 @@ impl<'r> Compiler<'r> {
209208
self.set_split(split, j3, j2);
210209
}
211210
}
212-
~Rep(x, OneMore, g) => {
211+
Rep(x, OneMore, g) => {
213212
let j1 = self.insts.len();
214-
self.compile(x);
213+
self.compile(*x);
215214
let split = self.empty_split();
216215
let j2 = self.insts.len();
217216

src/libregex/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@
362362
html_root_url = "http://static.rust-lang.org/doc/master")]
363363

364364
#![feature(macro_rules, phase)]
365-
#![deny(missing_doc)]
365+
#![deny(missing_doc, deprecated_owned_vector)]
366366

367367
extern crate collections;
368368
#[cfg(test)]

0 commit comments

Comments
 (0)