diff options
author | Eugene Kliuchnikov <eustas@google.com> | 2017-05-07 17:40:12 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-05-07 17:40:12 +0200 |
commit | 0a84e9bf864dfe3862bfe7b4e09650ff283c9825 (patch) | |
tree | b430d708df04344bcf3ca388840be5295b5a6ceb | |
parent | 4363f2d74b8af198f78b08e10cd0b3ead48af590 (diff) | |
download | brotli-0a84e9bf864dfe3862bfe7b4e09650ff283c9825.zip brotli-0a84e9bf864dfe3862bfe7b4e09650ff283c9825.tar.gz brotli-0a84e9bf864dfe3862bfe7b4e09650ff283c9825.tar.bz2 |
Transpile Java speedup (#548)
-rw-r--r-- | csharp/org/brotli/dec/Decode.cs | 37 |
1 files changed, 26 insertions, 11 deletions
diff --git a/csharp/org/brotli/dec/Decode.cs b/csharp/org/brotli/dec/Decode.cs index 8a75aa2..bdc8709 100644 --- a/csharp/org/brotli/dec/Decode.cs +++ b/csharp/org/brotli/dec/Decode.cs @@ -852,19 +852,34 @@ namespace Org.Brotli.Dec case Org.Brotli.Dec.RunningState.CopyLoop:
{
// fall through
- for (; state.j < state.copyLength; )
+ int src = (state.pos - state.distance) & ringBufferMask;
+ int dst = state.pos;
+ int copyLength = state.copyLength - state.j;
+ if ((src + copyLength < ringBufferMask) && (dst + copyLength < ringBufferMask))
{
- ringBuffer[state.pos] = ringBuffer[(state.pos - state.distance) & ringBufferMask];
- // TODO: condense
- state.metaBlockLength--;
- state.j++;
- if (state.pos++ == ringBufferMask)
+ for (int k = 0; k < copyLength; ++k)
{
- state.nextRunningState = Org.Brotli.Dec.RunningState.CopyLoop;
- state.bytesToWrite = state.ringBufferSize;
- state.bytesWritten = 0;
- state.runningState = Org.Brotli.Dec.RunningState.Write;
- break;
+ ringBuffer[dst++] = ringBuffer[src++];
+ }
+ state.j += copyLength;
+ state.metaBlockLength -= copyLength;
+ state.pos += copyLength;
+ }
+ else
+ {
+ for (; state.j < state.copyLength; )
+ {
+ ringBuffer[state.pos] = ringBuffer[(state.pos - state.distance) & ringBufferMask];
+ state.metaBlockLength--;
+ state.j++;
+ if (state.pos++ == ringBufferMask)
+ {
+ state.nextRunningState = Org.Brotli.Dec.RunningState.CopyLoop;
+ state.bytesToWrite = state.ringBufferSize;
+ state.bytesWritten = 0;
+ state.runningState = Org.Brotli.Dec.RunningState.Write;
+ break;
+ }
}
}
if (state.runningState == Org.Brotli.Dec.RunningState.CopyLoop)
|