Mercurial > hg4j
comparison 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 |
comparison
equal
deleted
inserted
replaced
574:88afffd39899 | 575:8bf184c9d733 |
---|---|
82 } | 82 } |
83 decompressedLength = 0; // guard to avoid endless loop in case length() would get invoked from below. | 83 decompressedLength = 0; // guard to avoid endless loop in case length() would get invoked from below. |
84 int c = 0; | 84 int c = 0; |
85 int oldPos = decompressedPos; | 85 int oldPos = decompressedPos; |
86 byte[] dummy = new byte[buffer.length]; | 86 byte[] dummy = new byte[buffer.length]; |
87 int toRead; | 87 try { |
88 while ((toRead = super.available()) > 0) { | 88 int toRead = -1; |
89 if (toRead > buffer.length) { | 89 do { |
90 toRead = buffer.length; | |
91 } | |
92 super.readBytes(buffer, 0, toRead); | |
93 inflater.setInput(buffer, 0, toRead); | |
94 try { | |
95 while (!inflater.needsInput()) { | 90 while (!inflater.needsInput()) { |
96 c += inflater.inflate(dummy, 0, dummy.length); | 91 c += inflater.inflate(dummy, 0, dummy.length); |
97 } | 92 } |
98 } catch (DataFormatException ex) { | 93 if (inflater.needsInput() && (toRead = super.available()) > 0) { |
99 throw new IOException(ex.toString()); | 94 // fill: |
100 } | 95 if (toRead > buffer.length) { |
96 toRead = buffer.length; | |
97 } | |
98 super.readBytes(buffer, 0, toRead); | |
99 inflater.setInput(buffer, 0, toRead); | |
100 } | |
101 } while(toRead > 0); | |
102 } catch (DataFormatException ex) { | |
103 throw new IOException(ex.toString()); | |
101 } | 104 } |
102 decompressedLength = c + oldPos; | 105 decompressedLength = c + oldPos; |
103 reset(); | 106 reset(); |
104 seek(oldPos); | 107 seek(oldPos); |
105 return decompressedLength; | 108 return decompressedLength; |