Skip to content

Remove c_literal and c_bytes methods #512

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 9, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 2 additions & 38 deletions src/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,11 +263,11 @@ impl Compiler {
match *expr.kind() {
Empty => Ok(Patch { hole: Hole::None, entry: self.insts.len() }),
Literal(hir::Literal::Unicode(c)) => {
self.c_literal(&[c])
self.c_char(c)
}
Literal(hir::Literal::Byte(b)) => {
assert!(self.compiled.uses_bytes());
self.c_bytes(&[b])
self.c_byte(b)
}
Class(hir::Class::Unicode(ref cls)) => {
self.c_class(cls.ranges())
Expand Down Expand Up @@ -395,24 +395,6 @@ impl Compiler {
})
}

fn c_literal(&mut self, chars: &[char]) -> Result {
debug_assert!(!chars.is_empty());
let mut chars: Box<Iterator<Item=&char>> =
if self.compiled.is_reverse {
Box::new(chars.iter().rev())
} else {
Box::new(chars.iter())
};
let first = *chars.next().expect("non-empty literal");
let Patch { mut hole, entry } = self.c_char(first)?;
for &c in chars {
let p = self.c_char(c)?;
self.fill(hole, p.entry);
hole = p.hole;
}
Ok(Patch { hole: hole, entry: entry })
}

fn c_char(&mut self, c: char) -> Result {
self.c_class(&[hir::ClassUnicodeRange::new(c, c)])
}
Expand All @@ -436,24 +418,6 @@ impl Compiler {
}
}

fn c_bytes(&mut self, bytes: &[u8]) -> Result {
debug_assert!(!bytes.is_empty());
let mut bytes: Box<Iterator<Item=&u8>> =
if self.compiled.is_reverse {
Box::new(bytes.iter().rev())
} else {
Box::new(bytes.iter())
};
let first = *bytes.next().expect("non-empty literal");
let Patch { mut hole, entry } = self.c_byte(first)?;
for &b in bytes {
let p = self.c_byte(b)?;
self.fill(hole, p.entry);
hole = p.hole;
}
Ok(Patch { hole: hole, entry: entry })
}

fn c_byte(&mut self, b: u8) -> Result {
self.c_class_bytes(&[hir::ClassBytesRange::new(b, b)])
}
Expand Down