Skip to content

Commit 2ac868a

Browse files
committed
Only call chunks_* once
1 parent 931f58d commit 2ac868a

File tree

1 file changed

+9
-14
lines changed

1 file changed

+9
-14
lines changed

src/predictor.rs

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
use std::fmt::Debug;
33

44
use bytes::{Bytes, BytesMut};
5-
// use tiff::decoder::DecodingResult;
65

6+
use crate::error::AsyncTiffError;
77
use crate::ImageFileDirectory;
88
use crate::{error::AsyncTiffResult, reader::Endianness};
99

@@ -78,12 +78,10 @@ impl PredictorInfo {
7878
///
7979
/// strips are considered image-width chunks
8080
fn chunk_width_pixels(&self, x: u32) -> AsyncTiffResult<u32> {
81-
if x >= self.chunks_across() {
82-
Err(crate::error::AsyncTiffError::TileIndexError(
83-
x,
84-
self.chunks_across(),
85-
))
86-
} else if x == self.chunks_across() - 1 {
81+
let chunks_across = self.chunks_across();
82+
if x >= chunks_across {
83+
Err(AsyncTiffError::TileIndexError(x, chunks_across))
84+
} else if x == chunks_across - 1 {
8785
// last chunk
8886
Ok(self.image_width - self.chunk_width * x)
8987
} else {
@@ -94,14 +92,11 @@ impl PredictorInfo {
9492
/// chunk height in pixels, taking padding into account
9593
///
9694
/// strips are considered image-width chunks
97-
///
9895
fn chunk_height_pixels(&self, y: u32) -> AsyncTiffResult<u32> {
99-
if y >= self.chunks_down() {
100-
Err(crate::error::AsyncTiffError::TileIndexError(
101-
y,
102-
self.chunks_down(),
103-
))
104-
} else if y == self.chunks_down() - 1 {
96+
let chunks_down = self.chunks_down();
97+
if y >= chunks_down {
98+
Err(AsyncTiffError::TileIndexError(y, chunks_down))
99+
} else if y == chunks_down - 1 {
105100
// last chunk
106101
Ok(self.image_height - self.chunk_height * y)
107102
} else {

0 commit comments

Comments
 (0)