Mercurial > hg4j
diff src/org/tmatesoft/hg/internal/InflaterDataAccess.java @ 575:8bf184c9d733
Issue 43: poor performance with InflaterDataAccess. Phase 1: test existing code, fix defects found
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Tue, 16 Apr 2013 16:59:59 +0200 |
parents | 2a08466838d3 |
children | 3c4db86e8c1f |
line wrap: on
line diff
--- a/src/org/tmatesoft/hg/internal/InflaterDataAccess.java Tue Apr 16 14:44:57 2013 +0200 +++ b/src/org/tmatesoft/hg/internal/InflaterDataAccess.java Tue Apr 16 16:59:59 2013 +0200 @@ -84,20 +84,23 @@ int c = 0; int oldPos = decompressedPos; byte[] dummy = new byte[buffer.length]; - int toRead; - while ((toRead = super.available()) > 0) { - if (toRead > buffer.length) { - toRead = buffer.length; - } - super.readBytes(buffer, 0, toRead); - inflater.setInput(buffer, 0, toRead); - try { + try { + int toRead = -1; + do { while (!inflater.needsInput()) { c += inflater.inflate(dummy, 0, dummy.length); } - } catch (DataFormatException ex) { - throw new IOException(ex.toString()); - } + if (inflater.needsInput() && (toRead = super.available()) > 0) { + // fill: + if (toRead > buffer.length) { + toRead = buffer.length; + } + super.readBytes(buffer, 0, toRead); + inflater.setInput(buffer, 0, toRead); + } + } while(toRead > 0); + } catch (DataFormatException ex) { + throw new IOException(ex.toString()); } decompressedLength = c + oldPos; reset();