This commit is contained in:
kennytm 2015-02-06 19:42:58 +08:00
parent 9fe75964ab
commit 068707d312
4 changed files with 23 additions and 23 deletions

View file

@ -457,7 +457,7 @@ impl Bits {
#[unstable]
pub fn push_byte_data(&mut self, data: &[u8]) -> QrResult<()> {
try!(self.push_header(Mode::Byte, data.len()));
for b in data.iter() {
for b in data {
self.push_number(8, *b as u16);
}
Ok(())
@ -754,7 +754,7 @@ mod finish_tests {
impl Bits {
/// Push a segmented data to the bits, and then terminate it.
pub fn push_segments<I>(&mut self, data: &[u8], mut segments_iter: I) -> QrResult<()>
pub fn push_segments<I>(&mut self, data: &[u8], segments_iter: I) -> QrResult<()>
where I: Iterator<Item=Segment>
{
for segment in segments_iter {
@ -823,8 +823,8 @@ mod encode_tests {
/// This method will not consider any Micro QR code versions.
pub fn encode_auto(data: &[u8], ec_level: EcLevel) -> QrResult<Bits> {
let segments = Parser::new(data).collect::<Vec<Segment>>();
for version in [Version::Normal(9), Version::Normal(26), Version::Normal(40)].iter() {
let opt_segments = Optimizer::new(segments.iter().map(|s| *s), *version).collect::<Vec<Segment>>();
for version in &[Version::Normal(9), Version::Normal(26), Version::Normal(40)] {
let opt_segments = Optimizer::new(segments.iter().map(|s| *s), *version).collect::<Vec<_>>();
let total_len = total_encoded_len(&*opt_segments, *version);
let data_capacity = version.fetch(ec_level, &DATA_LENGTHS).unwrap();
if total_len <= data_capacity {

View file

@ -111,9 +111,9 @@ impl Canvas {
fn to_debug_str(&self) -> String {
let width = self.width;
let mut res = String::with_capacity((width * (width + 1)) as usize);
for y in (0 .. width) {
for y in 0 .. width {
res.push('\n');
for x in (0 .. width) {
for x in 0 .. width {
res.push(match self.get(x, y) {
Module::Empty => '?',
Module::Light => '.',
@ -626,7 +626,7 @@ impl Canvas {
coords: &[(i16, i16)]) {
let zero: N = Int::zero();
let mut mask: N = !(!zero >> 1);
for &(x, y) in coords.iter() {
for &(x, y) in coords {
let color = if (mask & number) == zero { off_color } else { on_color };
self.put(x, y, color);
mask = mask >> 1;
@ -1428,8 +1428,8 @@ impl Canvas {
/// patterns.
pub fn apply_mask(&mut self, pattern: MaskPattern) {
let mask_fn = get_mask_function(pattern);
for x in (0 .. self.width) {
for y in (0 .. self.width) {
for x in 0 .. self.width {
for y in 0 .. self.width {
let module = self.get_mut(x, y);
*module = module.mask(mask_fn(x, y));
}
@ -1587,15 +1587,15 @@ impl Canvas {
fn compute_adjacent_penalty_score(&self, is_horizontal: bool) -> u16 {
let mut total_score = 0;
for i in (0 .. self.width) {
for i in 0 .. self.width {
let map_fn = |&:j| if is_horizontal {
self.get(j, i)
} else {
self.get(i, j)
};
let mut colors = (0 .. self.width).map(map_fn)
.chain(Some(Module::Empty).into_iter());
let colors = (0 .. self.width).map(map_fn)
.chain(Some(Module::Empty).into_iter());
let mut last_color = Module::Empty;
let mut consecutive_len = 1u16;
@ -1623,8 +1623,8 @@ impl Canvas {
fn compute_block_penalty_score(&self) -> u16 {
let mut total_score = 0;
for i in (0 .. self.width-1) {
for j in (0 .. self.width-1) {
for i in 0 .. self.width-1 {
for j in 0 .. self.width-1 {
let this = self.get(i, j);
let right = self.get(i+1, j);
let bottom = self.get(i, j+1);
@ -1651,8 +1651,8 @@ impl Canvas {
let mut total_score = 0;
for i in (0 .. self.width) {
for j in (0 .. self.width-6) {
for i in 0 .. self.width {
for j in 0 .. self.width-6 {
// TODO a ref to a closure should be enough?
let get: Box<Fn(i16) -> Module> = if is_horizontal {
Box::new(|&: k: i16| self.get(k, i))

View file

@ -24,7 +24,7 @@ pub fn create_error_correction_code(data: &[u8], ec_code_size: usize) -> Vec<u8>
let data_len = data.len();
let log_den = GENERATOR_POLYNOMIALS[ec_code_size];
for i in (0 .. data_len) {
for i in 0 .. data_len {
let lead_coeff = res[i] as usize;
if lead_coeff == 0 {
continue;
@ -76,8 +76,8 @@ mod ec_tests {
fn interleave<T: Copy, V: Deref<Target=[T]>>(blocks: &Vec<V>) -> Vec<T> {
let last_block_len = blocks.last().unwrap().len();
let mut res = Vec::with_capacity(last_block_len * blocks.len());
for i in (0 .. last_block_len) {
for t in blocks.iter() {
for i in 0 .. last_block_len {
for t in blocks {
if i < t.len() {
res.push(t[i]);
}

View file

@ -8,8 +8,8 @@
//! match code {
//! Err(err) => panic!("Failed to encode the QR code: {:?}", err),
//! Ok(code) => {
//! for y in (0 .. code.width()) {
//! for x in (0 .. code.width()) {
//! for y in 0 .. code.width() {
//! for x in 0 .. code.width() {
//! let color = if code[(x, y)] { "black" } else { "white" };
//! // render color at position (x, y)
//! }
@ -164,9 +164,9 @@ impl QrCode {
let width = self.width;
let mut k = 0;
let mut res = String::with_capacity(width * (width + 1));
for _ in (0 .. width) {
for _ in 0 .. width {
res.push('\n');
for _ in (0 .. width) {
for _ in 0 .. width {
res.push(if self.content[k] { on_char } else { off_char });
k += 1;
}