annotate src/org/tmatesoft/hg/internal/InflaterDataAccess.java @ 694:7efabe0cddcf

Speed up (a) file rename history to minimize file reads; (b) file.isCopy(int) to read metadata for few revisions at once (use pattern assumes earlier revisions are likely to be queried, too); (c) HgIgnore.isIgnored by caching matched initial fragments (to substitute more expensive Matcher.matches with cheaper HashMap.contains)
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Mon, 05 Aug 2013 17:42:10 +0200
parents bcbcc318f250
children
rev   line source
51
9429c7bd1920 Try DataAccess to reach revision data instead of plain byte arrays
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
1 /*
576
3c4db86e8c1f Issue 43: poor performance with InflaterDataAccess. Phase 2: inflate into buffer, effective skip and readByte/readBytes()
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 575
diff changeset
2 * Copyright (c) 2011-2013 TMate Software Ltd
157
d5268ca7715b Merged branch wrap-data-access into default for resource-friendly data access. Updated API to promote that friendliness to clients (channels, not byte[]). More exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 51
diff changeset
3 *
d5268ca7715b Merged branch wrap-data-access into default for resource-friendly data access. Updated API to promote that friendliness to clients (channels, not byte[]). More exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 51
diff changeset
4 * This program is free software; you can redistribute it and/or modify
d5268ca7715b Merged branch wrap-data-access into default for resource-friendly data access. Updated API to promote that friendliness to clients (channels, not byte[]). More exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 51
diff changeset
5 * it under the terms of the GNU General Public License as published by
d5268ca7715b Merged branch wrap-data-access into default for resource-friendly data access. Updated API to promote that friendliness to clients (channels, not byte[]). More exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 51
diff changeset
6 * the Free Software Foundation; version 2 of the License.
d5268ca7715b Merged branch wrap-data-access into default for resource-friendly data access. Updated API to promote that friendliness to clients (channels, not byte[]). More exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 51
diff changeset
7 *
d5268ca7715b Merged branch wrap-data-access into default for resource-friendly data access. Updated API to promote that friendliness to clients (channels, not byte[]). More exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 51
diff changeset
8 * This program is distributed in the hope that it will be useful,
d5268ca7715b Merged branch wrap-data-access into default for resource-friendly data access. Updated API to promote that friendliness to clients (channels, not byte[]). More exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 51
diff changeset
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
d5268ca7715b Merged branch wrap-data-access into default for resource-friendly data access. Updated API to promote that friendliness to clients (channels, not byte[]). More exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 51
diff changeset
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
d5268ca7715b Merged branch wrap-data-access into default for resource-friendly data access. Updated API to promote that friendliness to clients (channels, not byte[]). More exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 51
diff changeset
11 * GNU General Public License for more details.
d5268ca7715b Merged branch wrap-data-access into default for resource-friendly data access. Updated API to promote that friendliness to clients (channels, not byte[]). More exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 51
diff changeset
12 *
d5268ca7715b Merged branch wrap-data-access into default for resource-friendly data access. Updated API to promote that friendliness to clients (channels, not byte[]). More exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 51
diff changeset
13 * For information on how to redistribute this software under
d5268ca7715b Merged branch wrap-data-access into default for resource-friendly data access. Updated API to promote that friendliness to clients (channels, not byte[]). More exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 51
diff changeset
14 * the terms of a license other than GNU General Public License
d5268ca7715b Merged branch wrap-data-access into default for resource-friendly data access. Updated API to promote that friendliness to clients (channels, not byte[]). More exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 51
diff changeset
15 * contact TMate Software at support@hg4j.com
51
9429c7bd1920 Try DataAccess to reach revision data instead of plain byte arrays
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
16 */
157
d5268ca7715b Merged branch wrap-data-access into default for resource-friendly data access. Updated API to promote that friendliness to clients (channels, not byte[]). More exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 51
diff changeset
17 package org.tmatesoft.hg.internal;
51
9429c7bd1920 Try DataAccess to reach revision data instead of plain byte arrays
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
18
584
ed243b668502 Conditionally enable effective patch merge alternative for revlog reading
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 576
diff changeset
19 import java.io.EOFException;
51
9429c7bd1920 Try DataAccess to reach revision data instead of plain byte arrays
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
20 import java.io.IOException;
576
3c4db86e8c1f Issue 43: poor performance with InflaterDataAccess. Phase 2: inflate into buffer, effective skip and readByte/readBytes()
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 575
diff changeset
21 import java.nio.ByteBuffer;
51
9429c7bd1920 Try DataAccess to reach revision data instead of plain byte arrays
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
22 import java.util.zip.DataFormatException;
9429c7bd1920 Try DataAccess to reach revision data instead of plain byte arrays
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
23 import java.util.zip.Inflater;
9429c7bd1920 Try DataAccess to reach revision data instead of plain byte arrays
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
24 import java.util.zip.ZipException;
9429c7bd1920 Try DataAccess to reach revision data instead of plain byte arrays
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
25
9429c7bd1920 Try DataAccess to reach revision data instead of plain byte arrays
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
26 /**
9429c7bd1920 Try DataAccess to reach revision data instead of plain byte arrays
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
27 * DataAccess counterpart for InflaterInputStream.
9429c7bd1920 Try DataAccess to reach revision data instead of plain byte arrays
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
28 * XXX is it really needed to be subclass of FilterDataAccess?
157
d5268ca7715b Merged branch wrap-data-access into default for resource-friendly data access. Updated API to promote that friendliness to clients (channels, not byte[]). More exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 51
diff changeset
29 *
d5268ca7715b Merged branch wrap-data-access into default for resource-friendly data access. Updated API to promote that friendliness to clients (channels, not byte[]). More exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 51
diff changeset
30 * @author Artem Tikhomirov
d5268ca7715b Merged branch wrap-data-access into default for resource-friendly data access. Updated API to promote that friendliness to clients (channels, not byte[]). More exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 51
diff changeset
31 * @author TMate Software Ltd.
51
9429c7bd1920 Try DataAccess to reach revision data instead of plain byte arrays
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
32 */
9429c7bd1920 Try DataAccess to reach revision data instead of plain byte arrays
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
33 public class InflaterDataAccess extends FilterDataAccess {
9429c7bd1920 Try DataAccess to reach revision data instead of plain byte arrays
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
34
9429c7bd1920 Try DataAccess to reach revision data instead of plain byte arrays
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
35 private final Inflater inflater;
576
3c4db86e8c1f Issue 43: poor performance with InflaterDataAccess. Phase 2: inflate into buffer, effective skip and readByte/readBytes()
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 575
diff changeset
36 private final byte[] inBuffer;
3c4db86e8c1f Issue 43: poor performance with InflaterDataAccess. Phase 2: inflate into buffer, effective skip and readByte/readBytes()
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 575
diff changeset
37 private final ByteBuffer outBuffer;
3c4db86e8c1f Issue 43: poor performance with InflaterDataAccess. Phase 2: inflate into buffer, effective skip and readByte/readBytes()
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 575
diff changeset
38 private int inflaterPos = 0;
158
b413b16d10a5 Integer offsets and file length explictly, rather than casts throughout code. Inflater may benefit from total length hint, but shall calculate it by its own if needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 157
diff changeset
39 private int decompressedLength;
51
9429c7bd1920 Try DataAccess to reach revision data instead of plain byte arrays
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
40
420
6c22bdc0bdfd Respect long offsets in revlogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 399
diff changeset
41 public InflaterDataAccess(DataAccess dataAccess, long offset, int compressedLength) {
655
bcbcc318f250 Performance: reuse unzip output buffer
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 584
diff changeset
42 this(dataAccess, offset, compressedLength, -1, new Inflater(), new byte[512], null);
51
9429c7bd1920 Try DataAccess to reach revision data instead of plain byte arrays
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
43 }
9429c7bd1920 Try DataAccess to reach revision data instead of plain byte arrays
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
44
420
6c22bdc0bdfd Respect long offsets in revlogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 399
diff changeset
45 public InflaterDataAccess(DataAccess dataAccess, long offset, int compressedLength, int actualLength) {
655
bcbcc318f250 Performance: reuse unzip output buffer
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 584
diff changeset
46 this(dataAccess, offset, compressedLength, actualLength, new Inflater(), new byte[512], null);
158
b413b16d10a5 Integer offsets and file length explictly, rather than casts throughout code. Inflater may benefit from total length hint, but shall calculate it by its own if needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 157
diff changeset
47 }
b413b16d10a5 Integer offsets and file length explictly, rather than casts throughout code. Inflater may benefit from total length hint, but shall calculate it by its own if needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 157
diff changeset
48
655
bcbcc318f250 Performance: reuse unzip output buffer
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 584
diff changeset
49 public InflaterDataAccess(DataAccess dataAccess, long offset, int compressedLength, int actualLength, Inflater inflater, byte[] inBuf, ByteBuffer outBuf) {
158
b413b16d10a5 Integer offsets and file length explictly, rather than casts throughout code. Inflater may benefit from total length hint, but shall calculate it by its own if needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 157
diff changeset
50 super(dataAccess, offset, compressedLength);
655
bcbcc318f250 Performance: reuse unzip output buffer
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 584
diff changeset
51 if (inflater == null || inBuf == null) {
263
31f67be94e71 RevlogStream - reduce number of object instances, reuse when possible
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 158
diff changeset
52 throw new IllegalArgumentException();
31f67be94e71 RevlogStream - reduce number of object instances, reuse when possible
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 158
diff changeset
53 }
51
9429c7bd1920 Try DataAccess to reach revision data instead of plain byte arrays
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
54 this.inflater = inflater;
158
b413b16d10a5 Integer offsets and file length explictly, rather than casts throughout code. Inflater may benefit from total length hint, but shall calculate it by its own if needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 157
diff changeset
55 this.decompressedLength = actualLength;
655
bcbcc318f250 Performance: reuse unzip output buffer
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 584
diff changeset
56 inBuffer = inBuf;
bcbcc318f250 Performance: reuse unzip output buffer
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 584
diff changeset
57 outBuffer = outBuf == null ? ByteBuffer.allocate(inBuffer.length * 2) : outBuf;
576
3c4db86e8c1f Issue 43: poor performance with InflaterDataAccess. Phase 2: inflate into buffer, effective skip and readByte/readBytes()
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 575
diff changeset
58 outBuffer.limit(0); // there's nothing to read in the buffer
51
9429c7bd1920 Try DataAccess to reach revision data instead of plain byte arrays
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
59 }
9429c7bd1920 Try DataAccess to reach revision data instead of plain byte arrays
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
60
9429c7bd1920 Try DataAccess to reach revision data instead of plain byte arrays
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
61 @Override
157
d5268ca7715b Merged branch wrap-data-access into default for resource-friendly data access. Updated API to promote that friendliness to clients (channels, not byte[]). More exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 51
diff changeset
62 public InflaterDataAccess reset() throws IOException {
51
9429c7bd1920 Try DataAccess to reach revision data instead of plain byte arrays
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
63 super.reset();
9429c7bd1920 Try DataAccess to reach revision data instead of plain byte arrays
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
64 inflater.reset();
576
3c4db86e8c1f Issue 43: poor performance with InflaterDataAccess. Phase 2: inflate into buffer, effective skip and readByte/readBytes()
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 575
diff changeset
65 inflaterPos = 0;
3c4db86e8c1f Issue 43: poor performance with InflaterDataAccess. Phase 2: inflate into buffer, effective skip and readByte/readBytes()
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 575
diff changeset
66 outBuffer.clear().limit(0); // or flip(), to indicate nothing to read
157
d5268ca7715b Merged branch wrap-data-access into default for resource-friendly data access. Updated API to promote that friendliness to clients (channels, not byte[]). More exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 51
diff changeset
67 return this;
51
9429c7bd1920 Try DataAccess to reach revision data instead of plain byte arrays
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
68 }
9429c7bd1920 Try DataAccess to reach revision data instead of plain byte arrays
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
69
9429c7bd1920 Try DataAccess to reach revision data instead of plain byte arrays
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
70 @Override
421
fdd7d756dea0 Allow IOException from DataAccess methods for subclasses with non-trivial implementations, to avoid exception dumps when inapropriate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 420
diff changeset
71 protected int available() throws IOException {
576
3c4db86e8c1f Issue 43: poor performance with InflaterDataAccess. Phase 2: inflate into buffer, effective skip and readByte/readBytes()
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 575
diff changeset
72 return length() - decompressedPosition();
51
9429c7bd1920 Try DataAccess to reach revision data instead of plain byte arrays
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
73 }
9429c7bd1920 Try DataAccess to reach revision data instead of plain byte arrays
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
74
9429c7bd1920 Try DataAccess to reach revision data instead of plain byte arrays
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
75 @Override
421
fdd7d756dea0 Allow IOException from DataAccess methods for subclasses with non-trivial implementations, to avoid exception dumps when inapropriate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 420
diff changeset
76 public boolean isEmpty() throws IOException {
158
b413b16d10a5 Integer offsets and file length explictly, rather than casts throughout code. Inflater may benefit from total length hint, but shall calculate it by its own if needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 157
diff changeset
77 // can't use super.available() <= 0 because even when 0 < super.count < 6(?)
b413b16d10a5 Integer offsets and file length explictly, rather than casts throughout code. Inflater may benefit from total length hint, but shall calculate it by its own if needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 157
diff changeset
78 // decompressedPos might be already == length()
b413b16d10a5 Integer offsets and file length explictly, rather than casts throughout code. Inflater may benefit from total length hint, but shall calculate it by its own if needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 157
diff changeset
79 return available() <= 0;
51
9429c7bd1920 Try DataAccess to reach revision data instead of plain byte arrays
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
80 }
9429c7bd1920 Try DataAccess to reach revision data instead of plain byte arrays
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
81
9429c7bd1920 Try DataAccess to reach revision data instead of plain byte arrays
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
82 @Override
421
fdd7d756dea0 Allow IOException from DataAccess methods for subclasses with non-trivial implementations, to avoid exception dumps when inapropriate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 420
diff changeset
83 public int length() throws IOException {
51
9429c7bd1920 Try DataAccess to reach revision data instead of plain byte arrays
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
84 if (decompressedLength != -1) {
9429c7bd1920 Try DataAccess to reach revision data instead of plain byte arrays
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
85 return decompressedLength;
9429c7bd1920 Try DataAccess to reach revision data instead of plain byte arrays
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
86 }
576
3c4db86e8c1f Issue 43: poor performance with InflaterDataAccess. Phase 2: inflate into buffer, effective skip and readByte/readBytes()
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 575
diff changeset
87 decompressedLength = 0; // guard to avoid endless loop in case length() would get invoked from below.
3c4db86e8c1f Issue 43: poor performance with InflaterDataAccess. Phase 2: inflate into buffer, effective skip and readByte/readBytes()
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 575
diff changeset
88 final int oldPos = decompressedPosition();
3c4db86e8c1f Issue 43: poor performance with InflaterDataAccess. Phase 2: inflate into buffer, effective skip and readByte/readBytes()
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 575
diff changeset
89 final int inflatedUpTo = inflaterPos;
3c4db86e8c1f Issue 43: poor performance with InflaterDataAccess. Phase 2: inflate into buffer, effective skip and readByte/readBytes()
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 575
diff changeset
90 int inflatedMore = 0, c;
3c4db86e8c1f Issue 43: poor performance with InflaterDataAccess. Phase 2: inflate into buffer, effective skip and readByte/readBytes()
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 575
diff changeset
91 do {
3c4db86e8c1f Issue 43: poor performance with InflaterDataAccess. Phase 2: inflate into buffer, effective skip and readByte/readBytes()
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 575
diff changeset
92 outBuffer.limit(outBuffer.position()); // pretend the buffer is consumed
3c4db86e8c1f Issue 43: poor performance with InflaterDataAccess. Phase 2: inflate into buffer, effective skip and readByte/readBytes()
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 575
diff changeset
93 c = fillOutBuffer();
3c4db86e8c1f Issue 43: poor performance with InflaterDataAccess. Phase 2: inflate into buffer, effective skip and readByte/readBytes()
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 575
diff changeset
94 inflatedMore += c;
3c4db86e8c1f Issue 43: poor performance with InflaterDataAccess. Phase 2: inflate into buffer, effective skip and readByte/readBytes()
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 575
diff changeset
95 } while (c == outBuffer.capacity()); // once we unpacked less than capacity, input is over
3c4db86e8c1f Issue 43: poor performance with InflaterDataAccess. Phase 2: inflate into buffer, effective skip and readByte/readBytes()
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 575
diff changeset
96 decompressedLength = inflatedUpTo + inflatedMore;
421
fdd7d756dea0 Allow IOException from DataAccess methods for subclasses with non-trivial implementations, to avoid exception dumps when inapropriate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 420
diff changeset
97 reset();
fdd7d756dea0 Allow IOException from DataAccess methods for subclasses with non-trivial implementations, to avoid exception dumps when inapropriate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 420
diff changeset
98 seek(oldPos);
fdd7d756dea0 Allow IOException from DataAccess methods for subclasses with non-trivial implementations, to avoid exception dumps when inapropriate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 420
diff changeset
99 return decompressedLength;
51
9429c7bd1920 Try DataAccess to reach revision data instead of plain byte arrays
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
100 }
9429c7bd1920 Try DataAccess to reach revision data instead of plain byte arrays
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
101
9429c7bd1920 Try DataAccess to reach revision data instead of plain byte arrays
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
102 @Override
158
b413b16d10a5 Integer offsets and file length explictly, rather than casts throughout code. Inflater may benefit from total length hint, but shall calculate it by its own if needed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 157
diff changeset
103 public void seek(int localOffset) throws IOException {
51
9429c7bd1920 Try DataAccess to reach revision data instead of plain byte arrays
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
104 if (localOffset < 0 /* || localOffset >= length() */) {
9429c7bd1920 Try DataAccess to reach revision data instead of plain byte arrays
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
105 throw new IllegalArgumentException();
9429c7bd1920 Try DataAccess to reach revision data instead of plain byte arrays
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
106 }
576
3c4db86e8c1f Issue 43: poor performance with InflaterDataAccess. Phase 2: inflate into buffer, effective skip and readByte/readBytes()
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 575
diff changeset
107 int currentPos = decompressedPosition();
3c4db86e8c1f Issue 43: poor performance with InflaterDataAccess. Phase 2: inflate into buffer, effective skip and readByte/readBytes()
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 575
diff changeset
108 if (localOffset >= currentPos) {
3c4db86e8c1f Issue 43: poor performance with InflaterDataAccess. Phase 2: inflate into buffer, effective skip and readByte/readBytes()
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 575
diff changeset
109 skip(localOffset - currentPos);
51
9429c7bd1920 Try DataAccess to reach revision data instead of plain byte arrays
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
110 } else {
9429c7bd1920 Try DataAccess to reach revision data instead of plain byte arrays
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
111 reset();
420
6c22bdc0bdfd Respect long offsets in revlogs
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 399
diff changeset
112 skip(localOffset);
51
9429c7bd1920 Try DataAccess to reach revision data instead of plain byte arrays
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
113 }
9429c7bd1920 Try DataAccess to reach revision data instead of plain byte arrays
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
114 }
9429c7bd1920 Try DataAccess to reach revision data instead of plain byte arrays
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
115
9429c7bd1920 Try DataAccess to reach revision data instead of plain byte arrays
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
116 @Override
391
856517285256 Provide more details about exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 263
diff changeset
117 public void skip(final int bytesToSkip) throws IOException {
856517285256 Provide more details about exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 263
diff changeset
118 int bytes = bytesToSkip;
51
9429c7bd1920 Try DataAccess to reach revision data instead of plain byte arrays
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
119 if (bytes < 0) {
576
3c4db86e8c1f Issue 43: poor performance with InflaterDataAccess. Phase 2: inflate into buffer, effective skip and readByte/readBytes()
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 575
diff changeset
120 bytes += decompressedPosition();
51
9429c7bd1920 Try DataAccess to reach revision data instead of plain byte arrays
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
121 if (bytes < 0) {
576
3c4db86e8c1f Issue 43: poor performance with InflaterDataAccess. Phase 2: inflate into buffer, effective skip and readByte/readBytes()
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 575
diff changeset
122 throw new IOException(String.format("Underflow. Rewind past start of the slice. To skip:%d, decPos:%d, decLen:%d. Left:%d", bytesToSkip, inflaterPos, decompressedLength, bytes));
51
9429c7bd1920 Try DataAccess to reach revision data instead of plain byte arrays
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
123 }
9429c7bd1920 Try DataAccess to reach revision data instead of plain byte arrays
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
124 reset();
9429c7bd1920 Try DataAccess to reach revision data instead of plain byte arrays
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
125 // fall-through
9429c7bd1920 Try DataAccess to reach revision data instead of plain byte arrays
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
126 }
9429c7bd1920 Try DataAccess to reach revision data instead of plain byte arrays
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
127 while (!isEmpty() && bytes > 0) {
576
3c4db86e8c1f Issue 43: poor performance with InflaterDataAccess. Phase 2: inflate into buffer, effective skip and readByte/readBytes()
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 575
diff changeset
128 int fromBuffer = outBuffer.remaining();
3c4db86e8c1f Issue 43: poor performance with InflaterDataAccess. Phase 2: inflate into buffer, effective skip and readByte/readBytes()
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 575
diff changeset
129 if (fromBuffer > 0) {
3c4db86e8c1f Issue 43: poor performance with InflaterDataAccess. Phase 2: inflate into buffer, effective skip and readByte/readBytes()
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 575
diff changeset
130 if (fromBuffer >= bytes) {
3c4db86e8c1f Issue 43: poor performance with InflaterDataAccess. Phase 2: inflate into buffer, effective skip and readByte/readBytes()
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 575
diff changeset
131 outBuffer.position(outBuffer.position() + bytes);
3c4db86e8c1f Issue 43: poor performance with InflaterDataAccess. Phase 2: inflate into buffer, effective skip and readByte/readBytes()
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 575
diff changeset
132 bytes = 0;
3c4db86e8c1f Issue 43: poor performance with InflaterDataAccess. Phase 2: inflate into buffer, effective skip and readByte/readBytes()
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 575
diff changeset
133 break;
3c4db86e8c1f Issue 43: poor performance with InflaterDataAccess. Phase 2: inflate into buffer, effective skip and readByte/readBytes()
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 575
diff changeset
134 } else {
3c4db86e8c1f Issue 43: poor performance with InflaterDataAccess. Phase 2: inflate into buffer, effective skip and readByte/readBytes()
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 575
diff changeset
135 bytes -= fromBuffer;
3c4db86e8c1f Issue 43: poor performance with InflaterDataAccess. Phase 2: inflate into buffer, effective skip and readByte/readBytes()
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 575
diff changeset
136 outBuffer.limit(outBuffer.position()); // mark consumed
3c4db86e8c1f Issue 43: poor performance with InflaterDataAccess. Phase 2: inflate into buffer, effective skip and readByte/readBytes()
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 575
diff changeset
137 // fall through to fill the buffer
3c4db86e8c1f Issue 43: poor performance with InflaterDataAccess. Phase 2: inflate into buffer, effective skip and readByte/readBytes()
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 575
diff changeset
138 }
3c4db86e8c1f Issue 43: poor performance with InflaterDataAccess. Phase 2: inflate into buffer, effective skip and readByte/readBytes()
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 575
diff changeset
139 }
3c4db86e8c1f Issue 43: poor performance with InflaterDataAccess. Phase 2: inflate into buffer, effective skip and readByte/readBytes()
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 575
diff changeset
140 fillOutBuffer();
51
9429c7bd1920 Try DataAccess to reach revision data instead of plain byte arrays
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
141 }
9429c7bd1920 Try DataAccess to reach revision data instead of plain byte arrays
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
142 if (bytes != 0) {
576
3c4db86e8c1f Issue 43: poor performance with InflaterDataAccess. Phase 2: inflate into buffer, effective skip and readByte/readBytes()
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 575
diff changeset
143 throw new IOException(String.format("Underflow. Rewind past end of the slice. To skip:%d, decPos:%d, decLen:%d. Left:%d", bytesToSkip, inflaterPos, decompressedLength, bytes));
51
9429c7bd1920 Try DataAccess to reach revision data instead of plain byte arrays
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
144 }
9429c7bd1920 Try DataAccess to reach revision data instead of plain byte arrays
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
145 }
9429c7bd1920 Try DataAccess to reach revision data instead of plain byte arrays
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
146
9429c7bd1920 Try DataAccess to reach revision data instead of plain byte arrays
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
147 @Override
9429c7bd1920 Try DataAccess to reach revision data instead of plain byte arrays
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
148 public byte readByte() throws IOException {
576
3c4db86e8c1f Issue 43: poor performance with InflaterDataAccess. Phase 2: inflate into buffer, effective skip and readByte/readBytes()
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 575
diff changeset
149 if (!outBuffer.hasRemaining()) {
3c4db86e8c1f Issue 43: poor performance with InflaterDataAccess. Phase 2: inflate into buffer, effective skip and readByte/readBytes()
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 575
diff changeset
150 fillOutBuffer();
3c4db86e8c1f Issue 43: poor performance with InflaterDataAccess. Phase 2: inflate into buffer, effective skip and readByte/readBytes()
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 575
diff changeset
151 }
3c4db86e8c1f Issue 43: poor performance with InflaterDataAccess. Phase 2: inflate into buffer, effective skip and readByte/readBytes()
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 575
diff changeset
152 return outBuffer.get();
51
9429c7bd1920 Try DataAccess to reach revision data instead of plain byte arrays
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
153 }
9429c7bd1920 Try DataAccess to reach revision data instead of plain byte arrays
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
154
9429c7bd1920 Try DataAccess to reach revision data instead of plain byte arrays
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
155 @Override
9429c7bd1920 Try DataAccess to reach revision data instead of plain byte arrays
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
156 public void readBytes(byte[] b, int off, int len) throws IOException {
584
ed243b668502 Conditionally enable effective patch merge alternative for revlog reading
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 576
diff changeset
157 int fromBuffer;
576
3c4db86e8c1f Issue 43: poor performance with InflaterDataAccess. Phase 2: inflate into buffer, effective skip and readByte/readBytes()
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 575
diff changeset
158 do {
584
ed243b668502 Conditionally enable effective patch merge alternative for revlog reading
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 576
diff changeset
159 fromBuffer = outBuffer.remaining();
576
3c4db86e8c1f Issue 43: poor performance with InflaterDataAccess. Phase 2: inflate into buffer, effective skip and readByte/readBytes()
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 575
diff changeset
160 if (fromBuffer > 0) {
3c4db86e8c1f Issue 43: poor performance with InflaterDataAccess. Phase 2: inflate into buffer, effective skip and readByte/readBytes()
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 575
diff changeset
161 if (fromBuffer >= len) {
3c4db86e8c1f Issue 43: poor performance with InflaterDataAccess. Phase 2: inflate into buffer, effective skip and readByte/readBytes()
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 575
diff changeset
162 outBuffer.get(b, off, len);
3c4db86e8c1f Issue 43: poor performance with InflaterDataAccess. Phase 2: inflate into buffer, effective skip and readByte/readBytes()
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 575
diff changeset
163 return;
3c4db86e8c1f Issue 43: poor performance with InflaterDataAccess. Phase 2: inflate into buffer, effective skip and readByte/readBytes()
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 575
diff changeset
164 } else {
3c4db86e8c1f Issue 43: poor performance with InflaterDataAccess. Phase 2: inflate into buffer, effective skip and readByte/readBytes()
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 575
diff changeset
165 outBuffer.get(b, off, fromBuffer);
3c4db86e8c1f Issue 43: poor performance with InflaterDataAccess. Phase 2: inflate into buffer, effective skip and readByte/readBytes()
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 575
diff changeset
166 off += fromBuffer;
3c4db86e8c1f Issue 43: poor performance with InflaterDataAccess. Phase 2: inflate into buffer, effective skip and readByte/readBytes()
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 575
diff changeset
167 len -= fromBuffer;
3c4db86e8c1f Issue 43: poor performance with InflaterDataAccess. Phase 2: inflate into buffer, effective skip and readByte/readBytes()
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 575
diff changeset
168 // fall-through
3c4db86e8c1f Issue 43: poor performance with InflaterDataAccess. Phase 2: inflate into buffer, effective skip and readByte/readBytes()
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 575
diff changeset
169 }
3c4db86e8c1f Issue 43: poor performance with InflaterDataAccess. Phase 2: inflate into buffer, effective skip and readByte/readBytes()
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 575
diff changeset
170 }
584
ed243b668502 Conditionally enable effective patch merge alternative for revlog reading
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 576
diff changeset
171 fromBuffer = fillOutBuffer();
ed243b668502 Conditionally enable effective patch merge alternative for revlog reading
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 576
diff changeset
172 } while (len > 0 && fromBuffer > 0);
ed243b668502 Conditionally enable effective patch merge alternative for revlog reading
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 576
diff changeset
173 if (len > 0) {
ed243b668502 Conditionally enable effective patch merge alternative for revlog reading
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 576
diff changeset
174 // prevent hang up in this cycle if no more data is available, see Issue 25
ed243b668502 Conditionally enable effective patch merge alternative for revlog reading
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 576
diff changeset
175 throw new EOFException(String.format("No more compressed data is available to satisfy request for %d bytes. [finished:%b, needDict:%b, needInp:%b, available:%d", len, inflater.finished(), inflater.needsDictionary(), inflater.needsInput(), super.available()));
ed243b668502 Conditionally enable effective patch merge alternative for revlog reading
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 576
diff changeset
176 }
576
3c4db86e8c1f Issue 43: poor performance with InflaterDataAccess. Phase 2: inflate into buffer, effective skip and readByte/readBytes()
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 575
diff changeset
177 }
3c4db86e8c1f Issue 43: poor performance with InflaterDataAccess. Phase 2: inflate into buffer, effective skip and readByte/readBytes()
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 575
diff changeset
178
3c4db86e8c1f Issue 43: poor performance with InflaterDataAccess. Phase 2: inflate into buffer, effective skip and readByte/readBytes()
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 575
diff changeset
179 @Override
3c4db86e8c1f Issue 43: poor performance with InflaterDataAccess. Phase 2: inflate into buffer, effective skip and readByte/readBytes()
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 575
diff changeset
180 public void readBytes(ByteBuffer buf) throws IOException {
3c4db86e8c1f Issue 43: poor performance with InflaterDataAccess. Phase 2: inflate into buffer, effective skip and readByte/readBytes()
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 575
diff changeset
181 int len = Math.min(available(), buf.remaining());
3c4db86e8c1f Issue 43: poor performance with InflaterDataAccess. Phase 2: inflate into buffer, effective skip and readByte/readBytes()
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 575
diff changeset
182 while (len > 0) {
3c4db86e8c1f Issue 43: poor performance with InflaterDataAccess. Phase 2: inflate into buffer, effective skip and readByte/readBytes()
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 575
diff changeset
183 if (outBuffer.remaining() >= len) {
3c4db86e8c1f Issue 43: poor performance with InflaterDataAccess. Phase 2: inflate into buffer, effective skip and readByte/readBytes()
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 575
diff changeset
184 ByteBuffer slice = outBuffer.slice();
3c4db86e8c1f Issue 43: poor performance with InflaterDataAccess. Phase 2: inflate into buffer, effective skip and readByte/readBytes()
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 575
diff changeset
185 slice.limit(len);
3c4db86e8c1f Issue 43: poor performance with InflaterDataAccess. Phase 2: inflate into buffer, effective skip and readByte/readBytes()
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 575
diff changeset
186 buf.put(slice);
3c4db86e8c1f Issue 43: poor performance with InflaterDataAccess. Phase 2: inflate into buffer, effective skip and readByte/readBytes()
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 575
diff changeset
187 outBuffer.position(outBuffer.position() + len);
3c4db86e8c1f Issue 43: poor performance with InflaterDataAccess. Phase 2: inflate into buffer, effective skip and readByte/readBytes()
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 575
diff changeset
188 return;
3c4db86e8c1f Issue 43: poor performance with InflaterDataAccess. Phase 2: inflate into buffer, effective skip and readByte/readBytes()
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 575
diff changeset
189 } else {
3c4db86e8c1f Issue 43: poor performance with InflaterDataAccess. Phase 2: inflate into buffer, effective skip and readByte/readBytes()
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 575
diff changeset
190 len -= outBuffer.remaining();
3c4db86e8c1f Issue 43: poor performance with InflaterDataAccess. Phase 2: inflate into buffer, effective skip and readByte/readBytes()
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 575
diff changeset
191 buf.put(outBuffer);
3c4db86e8c1f Issue 43: poor performance with InflaterDataAccess. Phase 2: inflate into buffer, effective skip and readByte/readBytes()
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 575
diff changeset
192 }
3c4db86e8c1f Issue 43: poor performance with InflaterDataAccess. Phase 2: inflate into buffer, effective skip and readByte/readBytes()
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 575
diff changeset
193 fillOutBuffer();
3c4db86e8c1f Issue 43: poor performance with InflaterDataAccess. Phase 2: inflate into buffer, effective skip and readByte/readBytes()
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 575
diff changeset
194 }
3c4db86e8c1f Issue 43: poor performance with InflaterDataAccess. Phase 2: inflate into buffer, effective skip and readByte/readBytes()
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 575
diff changeset
195 }
3c4db86e8c1f Issue 43: poor performance with InflaterDataAccess. Phase 2: inflate into buffer, effective skip and readByte/readBytes()
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 575
diff changeset
196
3c4db86e8c1f Issue 43: poor performance with InflaterDataAccess. Phase 2: inflate into buffer, effective skip and readByte/readBytes()
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 575
diff changeset
197 private int decompressedPosition() {
3c4db86e8c1f Issue 43: poor performance with InflaterDataAccess. Phase 2: inflate into buffer, effective skip and readByte/readBytes()
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 575
diff changeset
198 assert outBuffer.remaining() <= inflaterPos;
3c4db86e8c1f Issue 43: poor performance with InflaterDataAccess. Phase 2: inflate into buffer, effective skip and readByte/readBytes()
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 575
diff changeset
199 return inflaterPos - outBuffer.remaining();
3c4db86e8c1f Issue 43: poor performance with InflaterDataAccess. Phase 2: inflate into buffer, effective skip and readByte/readBytes()
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 575
diff changeset
200 }
3c4db86e8c1f Issue 43: poor performance with InflaterDataAccess. Phase 2: inflate into buffer, effective skip and readByte/readBytes()
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 575
diff changeset
201
3c4db86e8c1f Issue 43: poor performance with InflaterDataAccess. Phase 2: inflate into buffer, effective skip and readByte/readBytes()
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 575
diff changeset
202 // after #fillOutBuffer(), outBuffer is ready for read
3c4db86e8c1f Issue 43: poor performance with InflaterDataAccess. Phase 2: inflate into buffer, effective skip and readByte/readBytes()
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 575
diff changeset
203 private int fillOutBuffer() throws IOException {
3c4db86e8c1f Issue 43: poor performance with InflaterDataAccess. Phase 2: inflate into buffer, effective skip and readByte/readBytes()
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 575
diff changeset
204 assert !outBuffer.hasRemaining();
51
9429c7bd1920 Try DataAccess to reach revision data instead of plain byte arrays
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
205 try {
576
3c4db86e8c1f Issue 43: poor performance with InflaterDataAccess. Phase 2: inflate into buffer, effective skip and readByte/readBytes()
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 575
diff changeset
206 int inflatedBytes = 0;
3c4db86e8c1f Issue 43: poor performance with InflaterDataAccess. Phase 2: inflate into buffer, effective skip and readByte/readBytes()
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 575
diff changeset
207 outBuffer.clear();
3c4db86e8c1f Issue 43: poor performance with InflaterDataAccess. Phase 2: inflate into buffer, effective skip and readByte/readBytes()
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 575
diff changeset
208 int len = outBuffer.capacity();
3c4db86e8c1f Issue 43: poor performance with InflaterDataAccess. Phase 2: inflate into buffer, effective skip and readByte/readBytes()
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 575
diff changeset
209 int off = 0;
3c4db86e8c1f Issue 43: poor performance with InflaterDataAccess. Phase 2: inflate into buffer, effective skip and readByte/readBytes()
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 575
diff changeset
210 do {
3c4db86e8c1f Issue 43: poor performance with InflaterDataAccess. Phase 2: inflate into buffer, effective skip and readByte/readBytes()
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 575
diff changeset
211 int n;
3c4db86e8c1f Issue 43: poor performance with InflaterDataAccess. Phase 2: inflate into buffer, effective skip and readByte/readBytes()
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 575
diff changeset
212 while ((n = inflater.inflate(outBuffer.array(), off, len)) == 0) {
399
fdc1db8f7f61 Issue 25: Underflow in InflaterDataAccess; test and fix for hang up when reading past end of compressed data (or zero-length data)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 391
diff changeset
213 // XXX few last bytes (checksum?) may be ignored by inflater, thus inflate may return 0 in
157
d5268ca7715b Merged branch wrap-data-access into default for resource-friendly data access. Updated API to promote that friendliness to clients (channels, not byte[]). More exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 51
diff changeset
214 // perfectly legal conditions (when all data already expanded, but there are still some bytes
399
fdc1db8f7f61 Issue 25: Underflow in InflaterDataAccess; test and fix for hang up when reading past end of compressed data (or zero-length data)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 391
diff changeset
215 // in the input stream)
fdc1db8f7f61 Issue 25: Underflow in InflaterDataAccess; test and fix for hang up when reading past end of compressed data (or zero-length data)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 391
diff changeset
216 int toRead = -1;
fdc1db8f7f61 Issue 25: Underflow in InflaterDataAccess; test and fix for hang up when reading past end of compressed data (or zero-length data)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 391
diff changeset
217 if (inflater.needsInput() && (toRead = super.available()) > 0) {
576
3c4db86e8c1f Issue 43: poor performance with InflaterDataAccess. Phase 2: inflate into buffer, effective skip and readByte/readBytes()
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 575
diff changeset
218 // fill
3c4db86e8c1f Issue 43: poor performance with InflaterDataAccess. Phase 2: inflate into buffer, effective skip and readByte/readBytes()
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 575
diff changeset
219 if (toRead > inBuffer.length) {
3c4db86e8c1f Issue 43: poor performance with InflaterDataAccess. Phase 2: inflate into buffer, effective skip and readByte/readBytes()
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 575
diff changeset
220 toRead = inBuffer.length;
51
9429c7bd1920 Try DataAccess to reach revision data instead of plain byte arrays
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
221 }
576
3c4db86e8c1f Issue 43: poor performance with InflaterDataAccess. Phase 2: inflate into buffer, effective skip and readByte/readBytes()
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 575
diff changeset
222 super.readBytes(inBuffer, 0, toRead);
3c4db86e8c1f Issue 43: poor performance with InflaterDataAccess. Phase 2: inflate into buffer, effective skip and readByte/readBytes()
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 575
diff changeset
223 inflater.setInput(inBuffer, 0, toRead);
399
fdc1db8f7f61 Issue 25: Underflow in InflaterDataAccess; test and fix for hang up when reading past end of compressed data (or zero-length data)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 391
diff changeset
224 } else {
576
3c4db86e8c1f Issue 43: poor performance with InflaterDataAccess. Phase 2: inflate into buffer, effective skip and readByte/readBytes()
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 575
diff changeset
225 // inflated nothing and doesn't want any more data (or no date available) - assume we're done
3c4db86e8c1f Issue 43: poor performance with InflaterDataAccess. Phase 2: inflate into buffer, effective skip and readByte/readBytes()
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 575
diff changeset
226 assert inflater.finished();
3c4db86e8c1f Issue 43: poor performance with InflaterDataAccess. Phase 2: inflate into buffer, effective skip and readByte/readBytes()
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 575
diff changeset
227 assert toRead <= 0;
3c4db86e8c1f Issue 43: poor performance with InflaterDataAccess. Phase 2: inflate into buffer, effective skip and readByte/readBytes()
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 575
diff changeset
228 break;
51
9429c7bd1920 Try DataAccess to reach revision data instead of plain byte arrays
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
229 }
9429c7bd1920 Try DataAccess to reach revision data instead of plain byte arrays
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
230 }
9429c7bd1920 Try DataAccess to reach revision data instead of plain byte arrays
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
231 off += n;
9429c7bd1920 Try DataAccess to reach revision data instead of plain byte arrays
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
232 len -= n;
576
3c4db86e8c1f Issue 43: poor performance with InflaterDataAccess. Phase 2: inflate into buffer, effective skip and readByte/readBytes()
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 575
diff changeset
233 inflatedBytes += n;
3c4db86e8c1f Issue 43: poor performance with InflaterDataAccess. Phase 2: inflate into buffer, effective skip and readByte/readBytes()
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 575
diff changeset
234 } while (len > 0 && !inflater.finished()); // either the buffer is filled or nothing more to unpack
3c4db86e8c1f Issue 43: poor performance with InflaterDataAccess. Phase 2: inflate into buffer, effective skip and readByte/readBytes()
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 575
diff changeset
235 inflaterPos += inflatedBytes;
3c4db86e8c1f Issue 43: poor performance with InflaterDataAccess. Phase 2: inflate into buffer, effective skip and readByte/readBytes()
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 575
diff changeset
236 outBuffer.limit(inflatedBytes);
3c4db86e8c1f Issue 43: poor performance with InflaterDataAccess. Phase 2: inflate into buffer, effective skip and readByte/readBytes()
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 575
diff changeset
237 assert outBuffer.position() == 0; // didn't change since #clear() above
3c4db86e8c1f Issue 43: poor performance with InflaterDataAccess. Phase 2: inflate into buffer, effective skip and readByte/readBytes()
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 575
diff changeset
238 return inflatedBytes;
51
9429c7bd1920 Try DataAccess to reach revision data instead of plain byte arrays
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
239 } catch (DataFormatException e) {
9429c7bd1920 Try DataAccess to reach revision data instead of plain byte arrays
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
240 String s = e.getMessage();
9429c7bd1920 Try DataAccess to reach revision data instead of plain byte arrays
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
241 throw new ZipException(s != null ? s : "Invalid ZLIB data format");
9429c7bd1920 Try DataAccess to reach revision data instead of plain byte arrays
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
242 }
9429c7bd1920 Try DataAccess to reach revision data instead of plain byte arrays
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
243 }
9429c7bd1920 Try DataAccess to reach revision data instead of plain byte arrays
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
244 }