Skip to content

Commit d260917

Browse files
committed
Initialize decoded up front.
We'll almost always end up with it, and it saves null checks (which can be easily forgotten - and *were* forgotten - elsewhere).
1 parent 23a1a12 commit d260917

File tree

1 file changed

+1
-6
lines changed

1 file changed

+1
-6
lines changed

src/vm/jvm/runtime/org/perl6/nqp/sixmodel/reprs/DecoderInstance.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public void configure(ThreadContext tc, String encoding, SixModelObject config)
2424
if (decoder == null) {
2525
charset = Charset.forName(encoding);
2626
decoder = charset.newDecoder();
27+
decoded = new ArrayList<CharBuffer>();
2728
lineSeps = new ArrayList<String>();
2829
lineSeps.add("\n");
2930
lineSeps.add("\r\n");
@@ -71,8 +72,6 @@ public String takeChars(ThreadContext tc, long chars) {
7172
String result = normalized.substring(0, (int)chars);
7273
String remaining = normalized.substring((int)chars, normalized.length());
7374
if (remaining.length() > 0) {
74-
if (decoded == null)
75-
decoded = new ArrayList<CharBuffer>();
7675
decoded.add(CharBuffer.wrap(remaining));
7776
}
7877
return result;
@@ -152,8 +151,6 @@ public String takeLine(ThreadContext tc, boolean chomp, boolean eof) {
152151
CharBuffer target = CharBuffer.allocate(decodee.limit());
153152
decoder.decode(decodee, target, eof && toDecode.size() == 1);
154153
target.rewind();
155-
if (decoded == null)
156-
decoded = new ArrayList<CharBuffer>();
157154
decoded.add(target);
158155
toDecode.remove(0);
159156
}
@@ -284,8 +281,6 @@ private CharBuffer decodedBuffer(CharBuffer buf) {
284281
}
285282

286283
private void forceDecodedBackToBytes() {
287-
if (decoded == null)
288-
return;
289284
for (int i = decoded.size() - 1; i >= 0; i--) {
290285
toDecode.add(0, charset.encode(decoded.get(i)));
291286
decoded.remove(i);

0 commit comments

Comments
 (0)