Skip to content
Permalink
Browse files
8261418: Reduce decoder creation overheads for sun.nio.cs.ext Charsets
Reviewed-by: naoto
  • Loading branch information
cl4es committed Feb 11, 2021
1 parent 5e1b809 commit 8b6ab31d313de61a0ef39722bc8e5fe0e10a8279
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2002, 2012, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2002, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -113,14 +113,10 @@ public class EUC_JP
byte[] sa = src.array();
int sp = src.arrayOffset() + src.position();
int sl = src.arrayOffset() + src.limit();
assert (sp <= sl);
sp = (sp <= sl ? sp : sl);

char[] da = dst.array();
int dp = dst.arrayOffset() + dst.position();
int dl = dst.arrayOffset() + dst.limit();
assert (dp <= dl);
dp = (dp <= dl ? dp : dl);

int b1 = 0, b2 = 0;
int inputSize = 0;
@@ -296,13 +292,10 @@ public class EUC_JP
char[] sa = src.array();
int sp = src.arrayOffset() + src.position();
int sl = src.arrayOffset() + src.limit();
assert (sp <= sl);
sp = (sp <= sl ? sp : sl);

byte[] da = dst.array();
int dp = dst.arrayOffset() + dst.position();
int dl = dst.arrayOffset() + dst.limit();
assert (dp <= dl);
dp = (dp <= dl ? dp : dl);

int outputSize = 0;
byte[] outputByte;
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2009, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -146,6 +146,19 @@ public class EUC_TW extends Charset implements HistoricallyNamedCharset
return b >= b1Min && b <= b1Max;
}

public static char decodeSingleOrReplace(int b1, int b2, int p, char replace) {
if (b1 < b1Min || b1 > b1Max || b2 < b2Min || b2 > b2Max)
return replace;
int index = (b1 - b1Min) * dbSegSize + b2 - b2Min;
char c = b2c[p].charAt(index);
if (c == UNMAPPABLE_DECODING)
return replace;
if ((b2cIsSupp[index] & (1 << p)) == 0) {
return c;
}
return replace;
}

static char[] decode(int b1, int b2, int p, char[] c1, char[] c2)
{
if (b1 < b1Min || b1 > b1Max || b2 < b2Min || b2 > b2Max)
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2002, 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2002, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -12332,14 +12332,10 @@ public class GB18030
byte[] sa = src.array();
int sp = src.arrayOffset() + src.position();
int sl = src.arrayOffset() + src.limit();
assert (sp <= sl);
sp = (sp <= sl ? sp : sl);

char[] da = dst.array();
int dp = dst.arrayOffset() + dst.position();
int dl = dst.arrayOffset() + dst.limit();
assert (dp <= dl);
dp = (dp <= dl ? dp : dl);

int inputSize = 1;

@@ -12585,13 +12581,10 @@ public class GB18030
char[] sa = src.array();
int sp = src.arrayOffset() + src.position();
int sl = src.arrayOffset() + src.limit();
assert (sp <= sl);
sp = (sp <= sl ? sp : sl);

byte[] da = dst.array();
int dp = dst.arrayOffset() + dst.position();
int dl = dst.arrayOffset() + dst.limit();
assert (dp <= dl);
dp = (dp <= dl ? dp : dl);

int condensedKey = 0; // expands to a four byte sequence
int hiByte = 0, loByte = 0;
@@ -212,14 +212,10 @@ public class IBM29626C
byte[] sa = src.array();
int sp = src.arrayOffset() + src.position();
int sl = src.arrayOffset() + src.limit();
assert (sp <= sl);
sp = (sp <= sl ? sp : sl);

char[] da = dst.array();
int dp = dst.arrayOffset() + dst.position();
int dl = dst.arrayOffset() + dst.limit();
assert (dp <= dl);
dp = (dp <= dl ? dp : dl);

int b1 = 0, b2 = 0;
int inputSize = 0;
@@ -484,13 +480,10 @@ public class IBM29626C
char[] sa = src.array();
int sp = src.arrayOffset() + src.position();
int sl = src.arrayOffset() + src.limit();
assert (sp <= sl);
sp = (sp <= sl ? sp : sl);

byte[] da = dst.array();
int dp = dst.arrayOffset() + dst.position();
int dl = dst.arrayOffset() + dst.limit();
assert (dp <= dl);
dp = (dp <= dl ? dp : dl);

int outputSize = 0;
byte[] outputByte;
@@ -1,6 +1,5 @@

/*
* Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -65,15 +64,8 @@ public CharsetEncoder newEncoder() {

protected static class Decoder extends CharsetDecoder {

private final int G0 = 0;
private final int G1 = 1;
private final int G2 = 2;
private final int G3 = 3;
private final int G4 = 4;
private final int SS2 = 0x8E;
private final int SS3 = 0x8F;

private int firstByte, state;
private static final int SS2 = 0x8E;
private static final int SS3 = 0x8F;

public Decoder(Charset cs) {
super(cs, 1.0f, 1.0f);
@@ -83,19 +75,16 @@ private CoderResult decodeArrayLoop(ByteBuffer src, CharBuffer dst) {
byte[] sa = src.array();
int sp = src.arrayOffset() + src.position();
int sl = src.arrayOffset() + src.limit();
assert (sp <= sl);
sp = (sp <= sl ? sp : sl);

char[] da = dst.array();
int dp = dst.arrayOffset() + dst.position();
int dl = dst.arrayOffset() + dst.limit();
assert (dp <= dl);
dp = (dp <= dl ? dp : dl);

try {
while (sp < sl) {
int byte1, byte2;
int inputSize = 1;
char outputChar = '\uFFFD';
char outputChar;
byte1 = sa[sp] & 0xff;

if (byte1 == SS2) {
@@ -157,7 +146,7 @@ private CoderResult decodeBufferLoop(ByteBuffer src, CharBuffer dst) {
while (src.hasRemaining()) {
int byte1, byte2;
int inputSize = 1;
char outputChar = '\uFFFD';
char outputChar;
byte1 = src.get() & 0xff;

if (byte1 == SS2) {
@@ -212,16 +201,16 @@ private CoderResult decodeBufferLoop(ByteBuffer src, CharBuffer dst) {
}

protected CoderResult decodeLoop(ByteBuffer src, CharBuffer dst) {
if (true && src.hasArray() && dst.hasArray())
if (src.hasArray() && dst.hasArray())
return decodeArrayLoop(src, dst);
else
return decodeBufferLoop(src, dst);
}

private final static String byteToCharTable;
private final static String mappingTableG1;
private final static String mappingTableG2;
private final static String mappingTableG3;
private static final String byteToCharTable;
private static final String mappingTableG1;
private static final String mappingTableG2;
private static final String mappingTableG3;
static {
byteToCharTable =
"\u0000\u0001\u0002\u0003\u0004\u0005\u0006\u0007" +
@@ -2749,9 +2738,9 @@ public Encoder(Charset cs) {
21792, 192, 73, 21824, 41, 2344, 2344, 0,
};

private final static String index2;
private final static String index2a;
private final static String index2b;
private static final String index2;
private static final String index2a;
private static final String index2b;
static {
index2 =
"\u0000\uA1F1\u0000\uA1F2\u0000\uA2CC\u0000\uA1B1\u0000\uA2C3" + // 0 - 4
@@ -1,6 +1,5 @@

/*
* Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -76,13 +75,10 @@ public class IBM964
byte[] sa = src.array();
int sp = src.arrayOffset() + src.position();
int sl = src.arrayOffset() + src.limit();
assert (sp <= sl);
sp = (sp <= sl ? sp : sl);

char[] da = dst.array();
int dp = dst.arrayOffset() + dst.position();
int dl = dst.arrayOffset() + dst.limit();
assert (dp <= dl);
dp = (dp <= dl ? dp : dl);

try {
while (sp < sl) {
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2002, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2002, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -500,14 +500,10 @@ private CoderResult decodeArrayLoop(ByteBuffer src,
byte[] sa = src.array();
int sp = src.arrayOffset() + src.position();
int sl = src.arrayOffset() + src.limit();
assert (sp <= sl);
sp = (sp <= sl ? sp : sl);

char[] da = dst.array();
int dp = dst.arrayOffset() + dst.position();
int dl = dst.arrayOffset() + dst.limit();
assert (dp <= dl);
dp = (dp <= dl ? dp : dl);

try {
while (sp < sl) {
@@ -821,15 +817,10 @@ private CoderResult encodeArrayLoop(CharBuffer src,
char[] sa = src.array();
int sp = src.arrayOffset() + src.position();
int sl = src.arrayOffset() + src.limit();
assert (sp <= sl);
sp = (sp <= sl ? sp : sl);

byte[] da = dst.array();
int dp = dst.arrayOffset() + dst.position();
int dl = dst.arrayOffset() + dst.limit();
assert (dp <= dl);
dp = (dp <= dl ? dp : dl);

int outputSize = 0;

try {
char inputChar;
Loading

0 comments on commit 8b6ab31

Please sign in to comment.