@@ -56,6 +56,8 @@ pub const BROTLI_SIMPLE_DISTANCE_ALPHABET_SIZE: usize = encode::BROTLI_NUM_DISTA
56
56
as usize
57
57
+ ( 2 * encode:: BROTLI_LARGE_MAX_DISTANCE_BITS as usize ) ;
58
58
59
+ const STORE_LOOKAHEAD_H_10 : usize = 128 ;
60
+
59
61
#[ inline( always) ]
60
62
pub fn BrotliInitZopfliNodes ( array : & mut [ ZopfliNode ] , length : usize ) {
61
63
let stub = ZopfliNode :: default ( ) ;
@@ -84,9 +86,7 @@ impl ZopfliNode {
84
86
. wrapping_add ( 9 )
85
87
. wrapping_sub ( self . length >> 25 )
86
88
}
87
- }
88
89
89
- impl ZopfliNode {
90
90
#[ inline( always) ]
91
91
fn distance_code ( & self ) -> u32 {
92
92
let short_code: u32 = self . dcode_insert_length >> 27 ;
@@ -205,11 +205,6 @@ impl Default for StartPosQueue {
205
205
}
206
206
}
207
207
208
- #[ inline( always) ]
209
- fn StoreLookaheadH10 ( ) -> usize {
210
- 128usize
211
- }
212
-
213
208
impl < AllocF : Allocator < floatX > > ZopfliCostModel < AllocF > {
214
209
fn init ( m : & mut AllocF , dist : & BrotliDistanceParams , num_bytes : usize ) -> Self {
215
210
Self {
@@ -266,11 +261,6 @@ impl<AllocF: Allocator<floatX>> ZopfliCostModel<AllocF> {
266
261
}
267
262
}
268
263
269
- #[ inline( always) ]
270
- fn InitStartPosQueue ( ) -> StartPosQueue {
271
- StartPosQueue :: default ( )
272
- }
273
-
274
264
#[ inline( always) ]
275
265
fn HashBytesH10 ( data : & [ u8 ] ) -> u32 {
276
266
let h: u32 = BROTLI_UNALIGNED_LOAD32 ( data) . wrapping_mul ( kHashMul32) ;
@@ -438,9 +428,11 @@ where
438
428
matches_offset
439
429
}
440
430
441
- #[ inline( always) ]
442
- fn BackwardMatchLength ( xself : & BackwardMatch ) -> usize {
443
- ( xself. length_and_code ( ) >> 5 ) as usize
431
+ impl BackwardMatch {
432
+ #[ inline( always) ]
433
+ fn length ( & self ) -> usize {
434
+ ( self . length_and_code ( ) >> 5 ) as usize
435
+ }
444
436
}
445
437
446
438
#[ inline( always) ]
@@ -518,22 +510,24 @@ fn ComputeDistanceCache(
518
510
}
519
511
}
520
512
521
- #[ inline( always) ]
522
- fn StartPosQueueSize ( xself : & StartPosQueue ) -> usize {
523
- min ( xself. idx_ , 8 )
524
- }
513
+ impl StartPosQueue {
514
+ #[ inline( always) ]
515
+ fn size ( & self ) -> usize {
516
+ min ( self . idx_ , 8 )
517
+ }
525
518
526
- fn StartPosQueuePush ( xself : & mut StartPosQueue , posdata : & PosData ) {
527
- let mut offset: usize = !xself. idx_ & 7usize ;
528
- xself. idx_ = xself. idx_ . wrapping_add ( 1 ) ;
529
- let len: usize = StartPosQueueSize ( xself) ;
530
- let q: & mut [ PosData ; 8 ] = & mut xself. q_ ;
531
- q[ offset] = * posdata;
532
- for _i in 1 ..len {
533
- if q[ offset & 7 ] . costdiff > q[ ( offset + 1 ) & 7 ] . costdiff {
534
- q. swap ( offset & 7 , ( offset + 1 ) & 7 ) ;
519
+ fn push ( & mut self , posdata : & PosData ) {
520
+ let mut offset: usize = !self . idx_ & 7usize ;
521
+ self . idx_ = self . idx_ . wrapping_add ( 1 ) ;
522
+ let len: usize = self . size ( ) ;
523
+ let q: & mut [ PosData ; 8 ] = & mut self . q_ ;
524
+ q[ offset] = * posdata;
525
+ for _i in 1 ..len {
526
+ if q[ offset & 7 ] . costdiff > q[ ( offset + 1 ) & 7 ] . costdiff {
527
+ q. swap ( offset & 7 , ( offset + 1 ) & 7 ) ;
528
+ }
529
+ offset = offset. wrapping_add ( 1 ) ;
535
530
}
536
- offset = offset. wrapping_add ( 1 ) ;
537
531
}
538
532
}
539
533
@@ -571,13 +565,15 @@ fn EvaluateNode<AllocF: Allocator<floatX>>(
571
565
nodes,
572
566
& mut posdata. distance_cache [ ..] ,
573
567
) ;
574
- StartPosQueuePush ( queue, & mut posdata) ;
568
+ queue. push ( & mut posdata) ;
575
569
}
576
570
}
577
571
578
- #[ inline( always) ]
579
- fn StartPosQueueAt ( xself : & StartPosQueue , k : usize ) -> & PosData {
580
- & xself. q_ [ ( k. wrapping_sub ( xself. idx_ ) & 7usize ) ]
572
+ impl StartPosQueue {
573
+ #[ inline( always) ]
574
+ fn at ( & self , k : usize ) -> & PosData {
575
+ & self . q_ [ k. wrapping_sub ( self . idx_ ) & 7usize ]
576
+ }
581
577
}
582
578
583
579
impl < AllocF : Allocator < floatX > > ZopfliCostModel < AllocF > {
@@ -655,13 +651,15 @@ fn UpdateZopfliNode(
655
651
next. u = Union1 :: cost ( cost) ;
656
652
}
657
653
658
- #[ inline( always) ]
659
- fn BackwardMatchLengthCode ( xself : & BackwardMatch ) -> usize {
660
- let code: usize = ( xself. length_and_code ( ) & 31u32 ) as usize ;
661
- if code != 0 {
662
- code
663
- } else {
664
- BackwardMatchLength ( xself)
654
+ impl BackwardMatch {
655
+ #[ inline( always) ]
656
+ fn length_code ( & self ) -> usize {
657
+ let code = ( self . length_and_code ( ) & 31u32 ) as usize ;
658
+ if code != 0 {
659
+ code
660
+ } else {
661
+ self . length ( )
662
+ }
665
663
}
666
664
}
667
665
@@ -701,16 +699,16 @@ fn UpdateNodes<AllocF: Allocator<floatX>>(
701
699
nodes,
702
700
) ;
703
701
{
704
- let posdata = StartPosQueueAt ( queue, 0usize ) ;
702
+ let posdata = queue. at ( 0 ) ;
705
703
let min_cost =
706
704
posdata. cost + model. get_min_cost_cmd ( ) + model. get_literal_costs ( posdata. pos , pos) ;
707
705
min_len = ComputeMinimumCopyLength ( min_cost, nodes, num_bytes, pos) ;
708
706
}
709
707
k = 0usize ;
710
- while k < max_iters && ( k < StartPosQueueSize ( queue) ) {
708
+ while k < max_iters && k < queue. size ( ) {
711
709
' continue28: loop {
712
710
{
713
- let posdata = StartPosQueueAt ( queue, k) ;
711
+ let posdata = queue. at ( k) ;
714
712
let start: usize = posdata. pos ;
715
713
let inscode: u16 = GetInsertLengthCode ( pos. wrapping_sub ( start) ) ;
716
714
let start_costdiff: floatX = posdata. costdiff ;
@@ -803,7 +801,7 @@ fn UpdateNodes<AllocF: Allocator<floatX>>(
803
801
{
804
802
let mut len: usize = min_len;
805
803
for j in 0usize ..num_matches {
806
- let mut match_: BackwardMatch = BackwardMatch ( matches[ j] ) ;
804
+ let match_ = BackwardMatch ( matches[ j] ) ;
807
805
let dist: usize = match_. distance ( ) as usize ;
808
806
let is_dictionary_match = dist > max_distance. wrapping_add ( gap) ;
809
807
let dist_code: usize = dist. wrapping_add ( 16 ) . wrapping_sub ( 1 ) ;
@@ -821,7 +819,7 @@ fn UpdateNodes<AllocF: Allocator<floatX>>(
821
819
let dist_cost = base_cost
822
820
+ ( distnumextra as floatX )
823
821
+ model. get_distance_cost ( ( dist_symbol as i32 & 0x03ff ) as usize ) ;
824
- let max_match_len: usize = BackwardMatchLength ( & mut match_) ;
822
+ let max_match_len = match_. length ( ) ;
825
823
if len < max_match_len
826
824
&& ( is_dictionary_match || max_match_len > max_zopfli_len)
827
825
{
@@ -830,7 +828,7 @@ fn UpdateNodes<AllocF: Allocator<floatX>>(
830
828
while len <= max_match_len {
831
829
{
832
830
let len_code: usize = if is_dictionary_match {
833
- BackwardMatchLengthCode ( & mut match_)
831
+ match_. length_code ( )
834
832
} else {
835
833
len
836
834
} ;
@@ -919,10 +917,10 @@ where
919
917
let mut model: ZopfliCostModel < AllocF > ;
920
918
let mut queue: StartPosQueue ;
921
919
let mut matches = [ 0 ; MAX_NUM_MATCHES_H10 ] ;
922
- let store_end: usize = if num_bytes >= StoreLookaheadH10 ( ) {
920
+ let store_end: usize = if num_bytes >= STORE_LOOKAHEAD_H_10 {
923
921
position
924
922
. wrapping_add ( num_bytes)
925
- . wrapping_sub ( StoreLookaheadH10 ( ) )
923
+ . wrapping_sub ( STORE_LOOKAHEAD_H_10 )
926
924
. wrapping_add ( 1 )
927
925
} else {
928
926
position
@@ -937,7 +935,7 @@ where
937
935
return 0usize ;
938
936
}
939
937
model. set_from_literal_costs ( position, ringbuffer, ringbuffer_mask) ;
940
- queue = InitStartPosQueue ( ) ;
938
+ queue = StartPosQueue :: default ( ) ;
941
939
i = 0usize ;
942
940
while i. wrapping_add ( handle. HashTypeLength ( ) ) . wrapping_sub ( 1 ) < num_bytes {
943
941
{
@@ -956,9 +954,8 @@ where
956
954
params,
957
955
& mut matches[ lz_matches_offset..] ,
958
956
) ;
959
- if num_matches > 0usize
960
- && ( BackwardMatchLength ( & BackwardMatch ( matches[ num_matches. wrapping_sub ( 1 ) ] ) )
961
- > max_zopfli_len)
957
+ if num_matches > 0
958
+ && BackwardMatch ( matches[ num_matches. wrapping_sub ( 1 ) ] ) . length ( ) > max_zopfli_len
962
959
{
963
960
matches[ 0 ] = matches[ num_matches. wrapping_sub ( 1 ) ] ;
964
961
num_matches = 1usize ;
@@ -981,10 +978,8 @@ where
981
978
if skip < 16384usize {
982
979
skip = 0usize ;
983
980
}
984
- if num_matches == 1usize
985
- && ( BackwardMatchLength ( & BackwardMatch ( matches[ 0 ] ) ) > max_zopfli_len)
986
- {
987
- skip = max ( BackwardMatchLength ( & BackwardMatch ( matches[ 0 ] ) ) , skip) ;
981
+ if num_matches == 1 && BackwardMatch ( matches[ 0 ] ) . length ( ) > max_zopfli_len {
982
+ skip = max ( BackwardMatch ( matches[ 0 ] ) . length ( ) , skip) ;
988
983
}
989
984
if skip > 1usize {
990
985
handle. StoreRange (
@@ -1228,7 +1223,7 @@ fn ZopfliIterate<AllocF: Allocator<floatX>>(
1228
1223
let mut i: usize ;
1229
1224
( nodes[ 0 ] ) . length = 0u32 ;
1230
1225
( nodes[ 0 ] ) . u = Union1 :: cost ( 0.0 ) ;
1231
- queue = InitStartPosQueue ( ) ;
1226
+ queue = StartPosQueue :: default ( ) ;
1232
1227
i = 0usize ;
1233
1228
while i. wrapping_add ( 3 ) < num_bytes {
1234
1229
{
@@ -1251,12 +1246,11 @@ fn ZopfliIterate<AllocF: Allocator<floatX>>(
1251
1246
skip = 0usize ;
1252
1247
}
1253
1248
cur_match_pos = cur_match_pos. wrapping_add ( num_matches[ i] as usize ) ;
1254
- if num_matches[ i] == 1u32
1255
- && ( BackwardMatchLength ( & BackwardMatch ( matches[ cur_match_pos. wrapping_sub ( 1 ) ] ) )
1256
- > max_zopfli_len)
1249
+ if num_matches[ i] == 1
1250
+ && BackwardMatch ( matches[ cur_match_pos. wrapping_sub ( 1 ) ] ) . length ( ) > max_zopfli_len
1257
1251
{
1258
1252
skip = max (
1259
- BackwardMatchLength ( & BackwardMatch ( matches[ cur_match_pos. wrapping_sub ( 1 ) ] ) ) ,
1253
+ BackwardMatch ( matches[ cur_match_pos. wrapping_sub ( 1 ) ] ) . length ( ) ,
1260
1254
skip,
1261
1255
) ;
1262
1256
}
@@ -1315,10 +1309,10 @@ pub fn BrotliCreateHqZopfliBackwardReferences<
1315
1309
<Alloc as Allocator < u32 > >:: AllocatedMemory :: default ( )
1316
1310
} ;
1317
1311
let mut matches_size: usize = ( 4usize ) . wrapping_mul ( num_bytes) ;
1318
- let store_end: usize = if num_bytes >= StoreLookaheadH10 ( ) {
1312
+ let store_end: usize = if num_bytes >= STORE_LOOKAHEAD_H_10 {
1319
1313
position
1320
1314
. wrapping_add ( num_bytes)
1321
- . wrapping_sub ( StoreLookaheadH10 ( ) )
1315
+ . wrapping_sub ( STORE_LOOKAHEAD_H_10 )
1322
1316
. wrapping_add ( 1 )
1323
1317
} else {
1324
1318
position
@@ -1402,9 +1396,8 @@ pub fn BrotliCreateHqZopfliBackwardReferences<
1402
1396
}
1403
1397
num_matches. slice_mut ( ) [ i] = num_found_matches as u32 ;
1404
1398
if num_found_matches > 0usize {
1405
- let match_len: usize = BackwardMatchLength ( & BackwardMatch (
1406
- matches. slice ( ) [ ( cur_match_end. wrapping_sub ( 1 ) as usize ) ] ,
1407
- ) ) ;
1399
+ let match_len =
1400
+ BackwardMatch ( matches. slice ( ) [ cur_match_end. wrapping_sub ( 1 ) ] ) . length ( ) ;
1408
1401
if match_len > 325usize {
1409
1402
let skip: usize = match_len. wrapping_sub ( 1 ) ;
1410
1403
let tmp = matches. slice ( ) [ ( cur_match_end. wrapping_sub ( 1 ) as usize ) ] ;
0 commit comments