Skip to content

Commit fe03d98

Browse files
Add debug asserts
1 parent 0f0007a commit fe03d98

3 files changed

Lines changed: 19 additions & 65 deletions

File tree

src/font/parser.rs

Lines changed: 15 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,18 @@
11
use super::grammar::{
2-
CMapFormat0,
3-
CMapFormat12,
4-
CMapFormat4,
5-
CMapIndividualGroup,
6-
CMapSubtable,
7-
CMapTable,
8-
ComponentGlyph,
9-
ComponentGlyphArgument,
10-
ComponentGlyphFlag,
11-
ComponentGlyphTransformation,
12-
CompoundGlyph,
13-
F2Dot14,
14-
FWord,
15-
Fixed,
16-
FontDirectory,
17-
Glyph,
18-
GlyphData,
19-
GlyphDescription,
20-
GlyphTable,
21-
HHeaTable,
22-
HMtxTable,
23-
HeadTable,
24-
LongDateTime,
25-
LongHorizontalMetric,
26-
MaxPTable,
27-
OffsetSubTable,
28-
ScalarType,
29-
SimpleGlyph,
30-
SimpleGlyphFlag,
31-
TableRecord,
32-
TableTag,
33-
TrueTypeFontFile,
34-
UnsignedFWord,
2+
CMapFormat0, CMapFormat12, CMapFormat4, CMapIndividualGroup, CMapSubtable, CMapTable,
3+
ComponentGlyph, ComponentGlyphArgument, ComponentGlyphFlag, ComponentGlyphTransformation,
4+
CompoundGlyph, F2Dot14, FWord, Fixed, FontDirectory, Glyph, GlyphData, GlyphDescription,
5+
GlyphTable, HHeaTable, HMtxTable, HeadTable, LongDateTime, LongHorizontalMetric, MaxPTable,
6+
OffsetSubTable, ScalarType, SimpleGlyph, SimpleGlyphFlag, TableRecord, TableTag,
7+
TrueTypeFontFile, UnsignedFWord,
358
};
369
use crate::{
3710
eof,
38-
font::grammar::{
39-
IndexToLocFormat,
40-
Platform,
41-
PlatformDouble,
42-
},
11+
font::grammar::{IndexToLocFormat, Platform, PlatformDouble},
4312
read,
44-
util::read_bytes::{
45-
U16_BYTES,
46-
U32_BYTES,
47-
U64_BYTES,
48-
U8_BYTES,
49-
},
50-
};
51-
use anyhow::{
52-
bail,
53-
ensure,
54-
Result,
13+
util::read_bytes::{U16_BYTES, U32_BYTES, U64_BYTES, U8_BYTES},
5514
};
15+
use anyhow::{bail, ensure, Result};
5616
use std::collections::BTreeMap;
5717

5818
#[derive(Debug)]
@@ -75,7 +35,7 @@ impl<'a> TrueTypeFontParser<'a> {
7535

7636
let offset = self.cursor;
7737
let head = self.parse_head_table()?;
78-
assert_eq!(self.cursor - offset, head_table_record.length as usize);
38+
debug_assert_eq!(self.cursor - offset, head_table_record.length as usize);
7939

8040
head
8141
};
@@ -86,7 +46,7 @@ impl<'a> TrueTypeFontParser<'a> {
8646

8747
let offset = self.cursor;
8848
let hhea = self.parse_hhea_table()?;
89-
assert_eq!(self.cursor - offset, hhea_table_record.length as usize);
49+
debug_assert_eq!(self.cursor - offset, hhea_table_record.length as usize);
9050

9151
hhea
9252
};
@@ -97,7 +57,7 @@ impl<'a> TrueTypeFontParser<'a> {
9757

9858
let offset = self.cursor;
9959
let maxp = self.parse_maxp_table()?;
100-
assert_eq!(self.cursor - offset, maxp_table_record.length as usize);
60+
debug_assert_eq!(self.cursor - offset, maxp_table_record.length as usize);
10161

10262
maxp
10363
};
@@ -110,7 +70,7 @@ impl<'a> TrueTypeFontParser<'a> {
11070
let loca =
11171
self.parse_loca_table(&head_table.index_to_loc_format, &maxp_table.num_glyphs)?;
11272

113-
assert_eq!(self.cursor - offset, loca_table_record.length as usize);
73+
debug_assert_eq!(self.cursor - offset, loca_table_record.length as usize);
11474

11575
loca
11676
};
@@ -122,7 +82,7 @@ impl<'a> TrueTypeFontParser<'a> {
12282
let offset = self.cursor;
12383
let htmx =
12484
self.parse_hmtx_table(hhea_table.num_of_long_hor_metrics, maxp_table.num_glyphs)?;
125-
assert_eq!(self.cursor - offset, hmtx_table_record.length as usize);
85+
debug_assert_eq!(self.cursor - offset, hmtx_table_record.length as usize);
12686

12787
htmx
12888
};
@@ -502,7 +462,7 @@ impl<'a> TrueTypeFontParser<'a> {
502462
glyphs.push(Glyph { description, data });
503463
}
504464

505-
assert_eq!(glyphs.len(), num_glyphs);
465+
debug_assert_eq!(glyphs.len(), num_glyphs);
506466

507467
Ok(GlyphTable { glyphs })
508468
}

src/png/scanline_reader.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
#![allow(clippy::needless_lifetimes)]
22

33
use crate::png::{
4-
grammar::{
5-
Filter,
6-
ImageHeader,
7-
},
4+
grammar::{Filter, ImageHeader},
85
interlace::compute_pass_counts,
96
};
107
use anyhow::Result;
@@ -19,7 +16,7 @@ impl<'a> ScanlineReader<'a> {
1916
pub(crate) fn new(input_buffer: &'a [u8], image_header: &'a ImageHeader) -> Self {
2017
let row_bytes = image_header.num_bytes_per_pixel() * image_header.width as usize;
2118

22-
assert_eq!(
19+
debug_assert_eq!(
2320
input_buffer.len() - image_header.height as usize,
2421
row_bytes * image_header.height as usize
2522
);

src/png/ssim.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
#![allow(clippy::suboptimal_flops)]
22

3-
use crate::png::grammar::{
4-
ColorType,
5-
Png,
6-
};
3+
use crate::png::grammar::{ColorType, Png};
74
use anyhow::ensure;
85

96
const K1: f32 = 0.01;
@@ -97,7 +94,7 @@ impl Png {
9794
let reference_luma_buffer = reference_image.luma_buffer();
9895
let test_luma_buffer = self.luma_buffer();
9996

100-
assert_eq!(
97+
debug_assert_eq!(
10198
reference_luma_buffer.lumas.len(),
10299
test_luma_buffer.lumas.len()
103100
);

0 commit comments

Comments
 (0)