Skip to content

Commit b87e1f1

Browse files
lukesandbergcgdecker
authored andcommitted
Automated g4 rollback of changelist 162220754.
*** Reason for rollback *** app-engine has a buggy implementation of FileInputStream.available() which is throwing IOException *** Original change description *** Implement ByteSource.asCharSource(charset).read() using the decoding string constructor instead of streaming the contents into a StringBuilder. this allows us to avoid a number of copies that are currently happening for each character (1. into a temporary CharBuffer, 2. into a StringBuilder, 3 into the String char[]) and replace it with simply whatever is required by ByteSource.read() and the String(byte[], charset) constructor. For certain ByteSource implementations (like FileByteSource) Byte... *** ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=162245286
1 parent 44b9081 commit b87e1f1

4 files changed

Lines changed: 0 additions & 298 deletions

File tree

android/guava-tests/benchmark/com/google/common/io/ByteSourceAsCharSourceReadBenchmark.java

Lines changed: 0 additions & 137 deletions
This file was deleted.

android/guava/src/com/google/common/io/ByteSource.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -455,18 +455,6 @@ public Reader openStream() throws IOException {
455455
return new InputStreamReader(ByteSource.this.openStream(), charset);
456456
}
457457

458-
@Override
459-
public String read() throws IOException {
460-
// Reading all the data as a byte array is more efficient than the default read()
461-
// implementation because:
462-
// 1. the string constructor can avoid an extra copy most of the time by correctly sizing the
463-
// internal char array (hard to avoid using StringBuilder)
464-
// 2. we avoid extra copies into temporary buffers altogether
465-
// The downside is that this will cause us to store the file bytes in memory twice for a short
466-
// amount of time.
467-
return new String(ByteSource.this.read(), charset);
468-
}
469-
470458
@Override
471459
public String toString() {
472460
return ByteSource.this.toString() + ".asCharSource(" + charset + ")";

guava-tests/benchmark/com/google/common/io/ByteSourceAsCharSourceReadBenchmark.java

Lines changed: 0 additions & 137 deletions
This file was deleted.

guava/src/com/google/common/io/ByteSource.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -455,18 +455,6 @@ public Reader openStream() throws IOException {
455455
return new InputStreamReader(ByteSource.this.openStream(), charset);
456456
}
457457

458-
@Override
459-
public String read() throws IOException {
460-
// Reading all the data as a byte array is more efficient than the default read()
461-
// implementation because:
462-
// 1. the string constructor can avoid an extra copy most of the time by correctly sizing the
463-
// internal char array (hard to avoid using StringBuilder)
464-
// 2. we avoid extra copies into temporary buffers altogether
465-
// The downside is that this will cause us to store the file bytes in memory twice for a short
466-
// amount of time.
467-
return new String(ByteSource.this.read(), charset);
468-
}
469-
470458
@Override
471459
public String toString() {
472460
return ByteSource.this.toString() + ".asCharSource(" + charset + ")";

0 commit comments

Comments
 (0)