Skip to content

Commit 0a84e9b

Browse files
authored
Transpile Java speedup (google#548)
1 parent 4363f2d commit 0a84e9b

File tree

1 file changed

+26
-11
lines changed

1 file changed

+26
-11
lines changed

csharp/org/brotli/dec/Decode.cs

+26-11
Original file line numberDiff line numberDiff line change
@@ -852,19 +852,34 @@ internal static void Decompress(Org.Brotli.Dec.State state)
852852
case Org.Brotli.Dec.RunningState.CopyLoop:
853853
{
854854
// fall through
855-
for (; state.j < state.copyLength; )
855+
int src = (state.pos - state.distance) & ringBufferMask;
856+
int dst = state.pos;
857+
int copyLength = state.copyLength - state.j;
858+
if ((src + copyLength < ringBufferMask) && (dst + copyLength < ringBufferMask))
856859
{
857-
ringBuffer[state.pos] = ringBuffer[(state.pos - state.distance) & ringBufferMask];
858-
// TODO: condense
859-
state.metaBlockLength--;
860-
state.j++;
861-
if (state.pos++ == ringBufferMask)
860+
for (int k = 0; k < copyLength; ++k)
862861
{
863-
state.nextRunningState = Org.Brotli.Dec.RunningState.CopyLoop;
864-
state.bytesToWrite = state.ringBufferSize;
865-
state.bytesWritten = 0;
866-
state.runningState = Org.Brotli.Dec.RunningState.Write;
867-
break;
862+
ringBuffer[dst++] = ringBuffer[src++];
863+
}
864+
state.j += copyLength;
865+
state.metaBlockLength -= copyLength;
866+
state.pos += copyLength;
867+
}
868+
else
869+
{
870+
for (; state.j < state.copyLength; )
871+
{
872+
ringBuffer[state.pos] = ringBuffer[(state.pos - state.distance) & ringBufferMask];
873+
state.metaBlockLength--;
874+
state.j++;
875+
if (state.pos++ == ringBufferMask)
876+
{
877+
state.nextRunningState = Org.Brotli.Dec.RunningState.CopyLoop;
878+
state.bytesToWrite = state.ringBufferSize;
879+
state.bytesWritten = 0;
880+
state.runningState = Org.Brotli.Dec.RunningState.Write;
881+
break;
882+
}
868883
}
869884
}
870885
if (state.runningState == Org.Brotli.Dec.RunningState.CopyLoop)

0 commit comments

Comments
 (0)