Skip to content

Commit e21c0af

Browse files
committed
Refactor: Use byte[] from ensureBufferSize() instead of always deferencing it from the context.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/codec/trunk@1378962 13f79535-47bb-0310-9956-ffa450edef68
1 parent dd86760 commit e21c0af

1 file changed

Lines changed: 21 additions & 21 deletions

File tree

  • src/main/java/org/apache/commons/codec/binary

src/main/java/org/apache/commons/codec/binary/Base32.java

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -295,19 +295,19 @@ void decode(byte[] in, int inPos, int inAvail, Context context) { // package pro
295295
context.eof = true;
296296
break;
297297
} else {
298-
ensureBufferSize(decodeSize, context);
298+
final byte[] buffer = ensureBufferSize(decodeSize, context);
299299
if (b >= 0 && b < this.decodeTable.length) {
300300
int result = this.decodeTable[b];
301301
if (result >= 0) {
302302
context.modulus = (context.modulus+1) % BYTES_PER_ENCODED_BLOCK;
303303
// collect decoded bytes
304304
context.lbitWorkArea = (context.lbitWorkArea << BITS_PER_ENCODED_BYTE) + result;
305305
if (context.modulus == 0) { // we can output the 5 bytes
306-
context.buffer[context.pos++] = (byte) ((context.lbitWorkArea >> 32) & MASK_8BITS);
307-
context.buffer[context.pos++] = (byte) ((context.lbitWorkArea >> 24) & MASK_8BITS);
308-
context.buffer[context.pos++] = (byte) ((context.lbitWorkArea >> 16) & MASK_8BITS);
309-
context.buffer[context.pos++] = (byte) ((context.lbitWorkArea >> 8) & MASK_8BITS);
310-
context.buffer[context.pos++] = (byte) (context.lbitWorkArea & MASK_8BITS);
306+
buffer[context.pos++] = (byte) ((context.lbitWorkArea >> 32) & MASK_8BITS);
307+
buffer[context.pos++] = (byte) ((context.lbitWorkArea >> 24) & MASK_8BITS);
308+
buffer[context.pos++] = (byte) ((context.lbitWorkArea >> 16) & MASK_8BITS);
309+
buffer[context.pos++] = (byte) ((context.lbitWorkArea >> 8) & MASK_8BITS);
310+
buffer[context.pos++] = (byte) (context.lbitWorkArea & MASK_8BITS);
311311
}
312312
}
313313
}
@@ -318,39 +318,39 @@ void decode(byte[] in, int inPos, int inAvail, Context context) { // package pro
318318
// EOF (-1) and first time '=' character is encountered in stream.
319319
// This approach makes the '=' padding characters completely optional.
320320
if (context.eof && context.modulus >= 2) { // if modulus < 2, nothing to do
321-
ensureBufferSize(decodeSize, context);
321+
final byte[] buffer = ensureBufferSize(decodeSize, context);
322322

323323
// we ignore partial bytes, i.e. only multiples of 8 count
324324
switch (context.modulus) {
325325
case 2 : // 10 bits, drop 2 and output one byte
326-
context.buffer[context.pos++] = (byte) ((context.lbitWorkArea >> 2) & MASK_8BITS);
326+
buffer[context.pos++] = (byte) ((context.lbitWorkArea >> 2) & MASK_8BITS);
327327
break;
328328
case 3 : // 15 bits, drop 7 and output 1 byte
329-
context.buffer[context.pos++] = (byte) ((context.lbitWorkArea >> 7) & MASK_8BITS);
329+
buffer[context.pos++] = (byte) ((context.lbitWorkArea >> 7) & MASK_8BITS);
330330
break;
331331
case 4 : // 20 bits = 2*8 + 4
332332
context.lbitWorkArea = context.lbitWorkArea >> 4; // drop 4 bits
333-
context.buffer[context.pos++] = (byte) ((context.lbitWorkArea >> 8) & MASK_8BITS);
334-
context.buffer[context.pos++] = (byte) ((context.lbitWorkArea) & MASK_8BITS);
333+
buffer[context.pos++] = (byte) ((context.lbitWorkArea >> 8) & MASK_8BITS);
334+
buffer[context.pos++] = (byte) ((context.lbitWorkArea) & MASK_8BITS);
335335
break;
336336
case 5 : // 25bits = 3*8 + 1
337337
context.lbitWorkArea = context.lbitWorkArea >> 1;
338-
context.buffer[context.pos++] = (byte) ((context.lbitWorkArea >> 16) & MASK_8BITS);
339-
context.buffer[context.pos++] = (byte) ((context.lbitWorkArea >> 8) & MASK_8BITS);
340-
context.buffer[context.pos++] = (byte) ((context.lbitWorkArea) & MASK_8BITS);
338+
buffer[context.pos++] = (byte) ((context.lbitWorkArea >> 16) & MASK_8BITS);
339+
buffer[context.pos++] = (byte) ((context.lbitWorkArea >> 8) & MASK_8BITS);
340+
buffer[context.pos++] = (byte) ((context.lbitWorkArea) & MASK_8BITS);
341341
break;
342342
case 6 : // 30bits = 3*8 + 6
343343
context.lbitWorkArea = context.lbitWorkArea >> 6;
344-
context.buffer[context.pos++] = (byte) ((context.lbitWorkArea >> 16) & MASK_8BITS);
345-
context.buffer[context.pos++] = (byte) ((context.lbitWorkArea >> 8) & MASK_8BITS);
346-
context.buffer[context.pos++] = (byte) ((context.lbitWorkArea) & MASK_8BITS);
344+
buffer[context.pos++] = (byte) ((context.lbitWorkArea >> 16) & MASK_8BITS);
345+
buffer[context.pos++] = (byte) ((context.lbitWorkArea >> 8) & MASK_8BITS);
346+
buffer[context.pos++] = (byte) ((context.lbitWorkArea) & MASK_8BITS);
347347
break;
348348
case 7 : // 35 = 4*8 +3
349349
context.lbitWorkArea = context.lbitWorkArea >> 3;
350-
context.buffer[context.pos++] = (byte) ((context.lbitWorkArea >> 24) & MASK_8BITS);
351-
context.buffer[context.pos++] = (byte) ((context.lbitWorkArea >> 16) & MASK_8BITS);
352-
context.buffer[context.pos++] = (byte) ((context.lbitWorkArea >> 8) & MASK_8BITS);
353-
context.buffer[context.pos++] = (byte) ((context.lbitWorkArea) & MASK_8BITS);
350+
buffer[context.pos++] = (byte) ((context.lbitWorkArea >> 24) & MASK_8BITS);
351+
buffer[context.pos++] = (byte) ((context.lbitWorkArea >> 16) & MASK_8BITS);
352+
buffer[context.pos++] = (byte) ((context.lbitWorkArea >> 8) & MASK_8BITS);
353+
buffer[context.pos++] = (byte) ((context.lbitWorkArea) & MASK_8BITS);
354354
break;
355355
}
356356
}

0 commit comments

Comments
 (0)