Skip to content

Commit

Permalink
Merge pull request #25 from skade/beta-1.0.0
Browse files Browse the repository at this point in the history
Replace usage of push_all and resize with extend
  • Loading branch information
Geal committed Apr 12, 2015
2 parents ee8ba80 + 90336c8 commit 0f14353
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 19 deletions.
9 changes: 4 additions & 5 deletions src/consumer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
//! This consumer will take 4 samples from the input, print them, then stop
//!
//! ```rust
//! #![feature(io)]
//! use nom::{IResult,Needed,MemProducer,Consumer,ConsumerState};
//! use std::str;
//! use std::io::SeekFrom;
Expand Down Expand Up @@ -113,7 +112,7 @@ pub trait Consumer {
let mut tmp = Vec::new();
//println!("before:\n{}", acc.to_hex(16));
//println!("after:\n{}", (&acc[consumed..acc.len()]).to_hex(16));
tmp.push_all(&acc[consumed..acc.len()]);
tmp.extend(acc[consumed..acc.len()].iter().cloned());
acc.clear();
acc = tmp;
} else {
Expand All @@ -124,7 +123,7 @@ pub trait Consumer {
acc.clear();
} else {
let mut tmp = Vec::new();
tmp.push_all(&acc[consumed..acc.len()]);
tmp.extend(acc[consumed..acc.len()].iter().cloned());
acc.clear();
acc = tmp;
}
Expand All @@ -134,7 +133,7 @@ pub trait Consumer {
match state {
Data(v) => {
//println!("got data: {} bytes", v.len());
acc.push_all(v);
acc.extend(v.iter().cloned());
position = position + v.len();
},
Eof(v) => {
Expand All @@ -146,7 +145,7 @@ pub trait Consumer {
} else {
//println!("eof with {} bytes", v.len());
eof = true;
acc.push_all(v);
acc.extend(v.iter().cloned());
position = position + v.len();
break;
}
Expand Down
2 changes: 0 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@
//! ```
//!
#![feature(collections)]

pub use self::util::*;
pub use self::internal::*;//{IResult, IResultClosure, GetInput, GetOutput};
pub use self::map::*;
Expand Down
2 changes: 0 additions & 2 deletions src/macros.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
extern crate collections;

#[macro_export]
macro_rules! closure (
($ty:ty, $submac:ident!( $($args:tt)* )) => (
Expand Down
2 changes: 0 additions & 2 deletions src/nom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
//! but the macros system makes no promises.
//!
extern crate collections;

use std::fmt::Debug;
use internal::*;
use internal::IResult::*;
Expand Down
12 changes: 7 additions & 5 deletions src/producer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ use std::fs::File;
use std::path::Path;
use std::io;
use std::io::{Read,Seek,SeekFrom};
use std::iter::repeat;

/// Holds the data producer's current state
///
Expand Down Expand Up @@ -78,9 +79,10 @@ impl FileProducer {

impl Producer for FileProducer {
fn produce(&mut self) -> ProducerState<&[u8]> {
let len = self.v.len();
//let mut v = Vec::with_capacity(self.size);
//self.v.clear();
self.v.resize(self.size, 0);
self.v.extend(repeat(0).take(self.size - len));
match self.file.read(&mut self.v) {
Err(e) => {
//println!("producer error: {:?}", e);
Expand Down Expand Up @@ -217,21 +219,21 @@ macro_rules! pusher (
match state {
ProducerState::Data(v) => {
//println!("got data");
acc.push_all(v)
acc.extend(v.iter().cloned())
},
ProducerState::Eof(v) => {
if v.is_empty() {
//println!("eof empty, acc contains {} bytes: {:?}", acc.len(), acc);
break;
} else {
//println!("eof with {} bytes", v.len());
acc.push_all(v)
acc.extend(v.iter().cloned())
}
}
_ => {break;}
}
let mut v2: Vec<u8> = Vec::new();
v2.push_all(&acc[..]);
v2.extend(acc[..].iter().cloned());
//let p = IResult::Done(b"", v2.as_slice());
match $f(&v2[..]) {
IResult::Error(e) => {
Expand All @@ -244,7 +246,7 @@ macro_rules! pusher (
IResult::Done(i, _) => {
//println!("data, done");
acc.clear();
acc.push_all(i);
acc.extend(i.iter().cloned());
}
}
}
Expand Down
1 change: 0 additions & 1 deletion tests/mp4.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![feature(log_syntax,trace_macros)]
#![allow(dead_code)]

#[macro_use]
Expand Down
2 changes: 0 additions & 2 deletions tests/test1.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![feature(collections,slice_patterns)]

#[macro_use]
extern crate nom;

Expand Down

0 comments on commit 0f14353

Please sign in to comment.