@@ -544,20 +544,18 @@ class Params {
544
544
final int offset ;
545
545
final int length ;
546
546
final boolean readResult ;
547
- final int repeatCount ;
548
547
549
- Params (Rope rope , int startingHashCode , int offset , int length , boolean readResult , int repeatCount ) {
548
+ Params (Rope rope , int startingHashCode , int offset , int length , boolean readResult ) {
550
549
this .rope = rope ;
551
550
this .startingHashCode = startingHashCode ;
552
551
this .offset = offset ;
553
552
this .length = length ;
554
553
this .readResult = readResult ;
555
- this .repeatCount = repeatCount ;
556
554
}
557
555
}
558
556
559
557
final Deque <Params > workStack = new ArrayDeque <>();
560
- workStack .push (new Params (rope , startingHashCode , offset , length , false , - 1 ));
558
+ workStack .push (new Params (rope , startingHashCode , offset , length , false ));
561
559
int resultHash = 0 ;
562
560
563
561
while (!workStack .isEmpty ()) {
@@ -572,14 +570,9 @@ class Params {
572
570
resultHash = Hashing .stringHash (bytes , startingHashCode , offset , length );
573
571
} else if (rope instanceof SubstringRope ) {
574
572
final SubstringRope substringRope = (SubstringRope ) rope ;
575
- workStack .push (
576
- new Params (
577
- substringRope .getChild (),
578
- startingHashCode ,
579
- offset + substringRope .getByteOffset (),
580
- length ,
581
- false ,
582
- -1 ));
573
+ final Rope child = substringRope .getChild ();
574
+ final int newOffset = offset + substringRope .getByteOffset ();
575
+ workStack .push (new Params (child , startingHashCode , newOffset , length , false ));
583
576
} else if (rope instanceof ConcatRope ) {
584
577
final ConcatRope concatRope = (ConcatRope ) rope ;
585
578
final Rope left = concatRope .getLeft ();
@@ -588,41 +581,35 @@ class Params {
588
581
589
582
if (offset >= leftLength ) {
590
583
// range fully contained in right child
591
- workStack .push (new Params (right , startingHashCode , offset - leftLength , length , false , - 1 ));
584
+ workStack .push (new Params (right , startingHashCode , offset - leftLength , length , false ));
592
585
} else if (offset + length <= leftLength ) {
593
586
// range fully contained in left child
594
- workStack .push (new Params (left , startingHashCode , offset , length , false , - 1 ));
587
+ workStack .push (new Params (left , startingHashCode , offset , length , false ));
595
588
} else {
596
589
final int coveredByLeft = leftLength - offset ;
597
590
// push right node first, starting hash is the result from the left node
598
- workStack .push (new Params (right , 0 , 0 , length - coveredByLeft , true , - 1 ));
599
- workStack .push (new Params (left , startingHashCode , offset , coveredByLeft , false , - 1 ));
591
+ workStack .push (new Params (right , 0 , 0 , length - coveredByLeft , true ));
592
+ workStack .push (new Params (left , startingHashCode , offset , coveredByLeft , false ));
600
593
}
601
594
} else if (rope instanceof RepeatingRope ) {
602
595
final RepeatingRope repeatingRope = (RepeatingRope ) rope ;
603
596
final Rope child = repeatingRope .getChild ();
604
597
final int patternLength = child .byteLength ();
605
598
606
- int count = params .repeatCount ;
607
- assert count != 0 ;
608
- if (count < 0 ) {
609
- offset %= patternLength ; // the offset is always 0 when count > 0
610
- count = computeLoopCount (offset , repeatingRope .getTimes (), length , patternLength );
611
- }
612
-
613
- if (count > 1 ) {
599
+ offset %= patternLength ;
600
+ if (length > patternLength - offset ) { // bytes to hash > bytes available in current repetition of child
614
601
// loop - 1 iteration, reset offset to 0, starting hash is the result from previous iteration
615
- workStack .push (new Params (rope , 0 , 0 , length - patternLength , true , count - 1 ));
602
+ workStack .push (new Params (rope , 0 , 0 , length - (patternLength - offset ), true ));
603
+ length = patternLength - offset ;
616
604
}
605
+
617
606
// one iteration
618
- final int bytesToHashThisPass = length + offset > patternLength
619
- ? patternLength - offset
620
- : length ;
621
- workStack .push (new Params (child , startingHashCode , offset , bytesToHashThisPass , false , -1 ));
607
+ workStack .push (new Params (child , startingHashCode , offset , length , false ));
622
608
} else {
623
609
resultHash = Hashing .stringHash (rope .getBytes (), startingHashCode , offset , length );
624
610
}
625
611
}
612
+
626
613
return resultHash ;
627
614
}
628
615
0 commit comments