8275863: Use encodeASCII for ASCII-compatible DoubleByte encodings
Reviewed-by: naoto, rriggs, alanb
This commit is contained in:
parent
2f979ecb5b
commit
6c05cc9d15
@ -151,6 +151,7 @@ module java.base {
|
|||||||
java.management,
|
java.management,
|
||||||
java.naming,
|
java.naming,
|
||||||
java.rmi,
|
java.rmi,
|
||||||
|
jdk.charsets,
|
||||||
jdk.jartool,
|
jdk.jartool,
|
||||||
jdk.jlink,
|
jdk.jlink,
|
||||||
jdk.net,
|
jdk.net,
|
||||||
|
@ -111,11 +111,11 @@ public class DoubleByte {
|
|||||||
Arrays.fill(B2C_UNMAPPABLE, UNMAPPABLE_DECODING);
|
Arrays.fill(B2C_UNMAPPABLE, UNMAPPABLE_DECODING);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static final JavaLangAccess JLA = SharedSecrets.getJavaLangAccess();
|
||||||
|
|
||||||
public static class Decoder extends CharsetDecoder
|
public static class Decoder extends CharsetDecoder
|
||||||
implements DelegatableDecoder, ArrayDecoder
|
implements DelegatableDecoder, ArrayDecoder
|
||||||
{
|
{
|
||||||
private static final JavaLangAccess JLA = SharedSecrets.getJavaLangAccess();
|
|
||||||
|
|
||||||
final char[][] b2c;
|
final char[][] b2c;
|
||||||
final char[] b2cSB;
|
final char[] b2cSB;
|
||||||
final int b2Min;
|
final int b2Min;
|
||||||
@ -601,6 +601,11 @@ public class DoubleByte {
|
|||||||
int dl = dst.arrayOffset() + dst.limit();
|
int dl = dst.arrayOffset() + dst.limit();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
if (isASCIICompatible) {
|
||||||
|
int n = JLA.encodeASCII(sa, sp, da, dp, Math.min(dl - dp, sl - sp));
|
||||||
|
sp += n;
|
||||||
|
dp += n;
|
||||||
|
}
|
||||||
while (sp < sl) {
|
while (sp < sl) {
|
||||||
char c = sa[sp];
|
char c = sa[sp];
|
||||||
int bb = encodeChar(c);
|
int bb = encodeChar(c);
|
||||||
@ -681,7 +686,11 @@ public class DoubleByte {
|
|||||||
public int encode(char[] src, int sp, int len, byte[] dst) {
|
public int encode(char[] src, int sp, int len, byte[] dst) {
|
||||||
int dp = 0;
|
int dp = 0;
|
||||||
int sl = sp + len;
|
int sl = sp + len;
|
||||||
int dl = dst.length;
|
if (isASCIICompatible) {
|
||||||
|
int n = JLA.encodeASCII(src, sp, dst, dp, len);
|
||||||
|
sp += n;
|
||||||
|
dp += n;
|
||||||
|
}
|
||||||
while (sp < sl) {
|
while (sp < sl) {
|
||||||
char c = src[sp++];
|
char c = src[sp++];
|
||||||
int bb = encodeChar(c);
|
int bb = encodeChar(c);
|
||||||
|
@ -42,9 +42,9 @@ public class HKSCS {
|
|||||||
static int b2Min = 0x40;
|
static int b2Min = 0x40;
|
||||||
static int b2Max = 0xfe;
|
static int b2Max = 0xfe;
|
||||||
|
|
||||||
private char[][] b2cBmp;
|
private final char[][] b2cBmp;
|
||||||
private char[][] b2cSupp;
|
private final char[][] b2cSupp;
|
||||||
private DoubleByte.Decoder big5Dec;
|
private final DoubleByte.Decoder big5Dec;
|
||||||
|
|
||||||
protected Decoder(Charset cs,
|
protected Decoder(Charset cs,
|
||||||
DoubleByte.Decoder big5Dec,
|
DoubleByte.Decoder big5Dec,
|
||||||
@ -94,7 +94,6 @@ public class HKSCS {
|
|||||||
int b1 = sa[sp] & 0xff;
|
int b1 = sa[sp] & 0xff;
|
||||||
char c = decodeSingle(b1);
|
char c = decodeSingle(b1);
|
||||||
int inSize = 1, outSize = 1;
|
int inSize = 1, outSize = 1;
|
||||||
char[] cc = null;
|
|
||||||
if (c == UNMAPPABLE_DECODING) {
|
if (c == UNMAPPABLE_DECODING) {
|
||||||
if (sl - sp < 2)
|
if (sl - sp < 2)
|
||||||
return CoderResult.UNDERFLOW;
|
return CoderResult.UNDERFLOW;
|
||||||
@ -137,7 +136,6 @@ public class HKSCS {
|
|||||||
int mark = src.position();
|
int mark = src.position();
|
||||||
try {
|
try {
|
||||||
while (src.hasRemaining()) {
|
while (src.hasRemaining()) {
|
||||||
char[] cc = null;
|
|
||||||
int b1 = src.get() & 0xff;
|
int b1 = src.get() & 0xff;
|
||||||
int inSize = 1, outSize = 1;
|
int inSize = 1, outSize = 1;
|
||||||
char c = decodeSingle(b1);
|
char c = decodeSingle(b1);
|
||||||
@ -230,9 +228,9 @@ public class HKSCS {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static class Encoder extends DoubleByte.Encoder {
|
public static class Encoder extends DoubleByte.Encoder {
|
||||||
private DoubleByte.Encoder big5Enc;
|
private final DoubleByte.Encoder big5Enc;
|
||||||
private char[][] c2bBmp;
|
private final char[][] c2bBmp;
|
||||||
private char[][] c2bSupp;
|
private final char[][] c2bSupp;
|
||||||
|
|
||||||
protected Encoder(Charset cs,
|
protected Encoder(Charset cs,
|
||||||
DoubleByte.Encoder big5Enc,
|
DoubleByte.Encoder big5Enc,
|
||||||
|
@ -111,6 +111,8 @@ grant codeBase "jrt:/jdk.accessibility" {
|
|||||||
grant codeBase "jrt:/jdk.charsets" {
|
grant codeBase "jrt:/jdk.charsets" {
|
||||||
permission java.util.PropertyPermission "os.name", "read";
|
permission java.util.PropertyPermission "os.name", "read";
|
||||||
permission java.lang.RuntimePermission "charsetProvider";
|
permission java.lang.RuntimePermission "charsetProvider";
|
||||||
|
permission java.lang.RuntimePermission
|
||||||
|
"accessClassInPackage.jdk.internal.access";
|
||||||
permission java.lang.RuntimePermission
|
permission java.lang.RuntimePermission
|
||||||
"accessClassInPackage.jdk.internal.misc";
|
"accessClassInPackage.jdk.internal.misc";
|
||||||
permission java.lang.RuntimePermission "accessClassInPackage.sun.nio.cs";
|
permission java.lang.RuntimePermission "accessClassInPackage.sun.nio.cs";
|
||||||
|
@ -25,6 +25,9 @@
|
|||||||
|
|
||||||
package $PACKAGE$;
|
package $PACKAGE$;
|
||||||
|
|
||||||
|
import jdk.internal.access.JavaLangAccess;
|
||||||
|
import jdk.internal.access.SharedSecrets;
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.CharBuffer;
|
import java.nio.CharBuffer;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
@ -43,6 +46,8 @@ public class EUC_JP
|
|||||||
extends Charset
|
extends Charset
|
||||||
implements HistoricallyNamedCharset
|
implements HistoricallyNamedCharset
|
||||||
{
|
{
|
||||||
|
private static final JavaLangAccess JLA = SharedSecrets.getJavaLangAccess();
|
||||||
|
|
||||||
public EUC_JP() {
|
public EUC_JP() {
|
||||||
super("EUC-JP", $ALIASES$);
|
super("EUC-JP", $ALIASES$);
|
||||||
}
|
}
|
||||||
@ -303,6 +308,11 @@ public class EUC_JP
|
|||||||
byte[] tmpBuf = new byte[3];
|
byte[] tmpBuf = new byte[3];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
if (enc0201.isASCIICompatible()) {
|
||||||
|
int n = JLA.encodeASCII(sa, sp, da, dp, Math.min(dl - dp, sl - sp));
|
||||||
|
sp += n;
|
||||||
|
dp += n;
|
||||||
|
}
|
||||||
while (sp < sl) {
|
while (sp < sl) {
|
||||||
outputByte = tmpBuf;
|
outputByte = tmpBuf;
|
||||||
char c = sa[sp];
|
char c = sa[sp];
|
||||||
|
Loading…
Reference in New Issue
Block a user