git://git.nikiroo.be
/
fanfix.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (from parent 1:
39d16a8
)
NextableInputStream: better perfs
author
Niki Roo
<niki@nikiroo.be>
Fri, 26 Apr 2019 16:16:21 +0000
(18:16 +0200)
committer
Niki Roo
<niki@nikiroo.be>
Fri, 26 Apr 2019 16:16:21 +0000
(18:16 +0200)
src/be/nikiroo/utils/NextableInputStream.java
patch
|
blob
|
blame
|
history
diff --git
a/src/be/nikiroo/utils/NextableInputStream.java
b/src/be/nikiroo/utils/NextableInputStream.java
index b5374a1329b88ce4944412830f4edb552c818b17..d9f27ceff87446bf2e6f5bfe49578b4bf687986c 100644
(file)
--- a/
src/be/nikiroo/utils/NextableInputStream.java
+++ b/
src/be/nikiroo/utils/NextableInputStream.java
@@
-224,6
+224,9
@@
public class NextableInputStream extends InputStream {
/**
* Check if this stream is totally spent (no more data to read or to
* process).
/**
* Check if this stream is totally spent (no more data to read or to
* process).
+ * <p>
+ * Note: an empty stream that is still not started will return FALSE, as we
+ * don't know yet if it is empty.
*
* @return TRUE if it is
*/
*
* @return TRUE if it is
*/
@@
-264,10
+267,11
@@
public class NextableInputStream extends InputStream {
while (hasMoreData() && done < blen) {
preRead();
if (hasMoreData()) {
while (hasMoreData() && done < blen) {
preRead();
if (hasMoreData()) {
- for (int i = pos; i < blen && i < len; i++) {
- b[boff + done] = buffer[i];
- pos++;
- done++;
+ int now = Math.min(blen, len) - pos;
+ if (now > 0) {
+ System.arraycopy(buffer, pos, b, boff, now);
+ pos += now;
+ done += now;
}
}
}
}
}
}
@@
-494,8
+498,7
@@
public class NextableInputStream extends InputStream {
}
// buffer must be > search
}
// buffer must be > search
- static private boolean startsWith(byte[] search, byte[] buffer,
- int offset) {
+ static private boolean startsWith(byte[] search, byte[] buffer, int offset) {
boolean same = true;
for (int i = 0; i < search.length; i++) {
if (search[i] != buffer[offset + i]) {
boolean same = true;
for (int i = 0; i < search.length; i++) {
if (search[i] != buffer[offset + i]) {