mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 23:04:50 +02:00
8231717: Improve performance of charset decoding when charset is always compactable
Reviewed-by: rriggs, redestad, alanb
This commit is contained in:
parent
4ad3d82c76
commit
0dbfc97c05
5 changed files with 66 additions and 6 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2009, 2019, 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
|
||||
|
@ -28,6 +28,9 @@ package sun.nio.cs;
|
|||
/*
|
||||
* FastPath byte[]->char[] decoder, REPLACE on malformed or
|
||||
* unmappable input.
|
||||
*
|
||||
* FastPath encoded byte[]-> "String Latin1 coding" byte[] decoder for use when
|
||||
* charset is always decodable to the internal String Latin1 coding byte[], ie. all mappings <=0xff
|
||||
*/
|
||||
|
||||
public interface ArrayDecoder {
|
||||
|
@ -36,4 +39,14 @@ public interface ArrayDecoder {
|
|||
default boolean isASCIICompatible() {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Is always decodable to internal String Latin1 coding, ie. all mappings <= 0xff
|
||||
default boolean isLatin1Decodable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Decode to internal String Latin1 coding byte[] fastpath for when isLatin1Decodable == true
|
||||
default int decodeToLatin1(byte[] src, int sp, int len, byte[] dst) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2008, 2012, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2008, 2019, 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
|
||||
|
@ -50,17 +50,27 @@ public class SingleByte
|
|||
implements ArrayDecoder {
|
||||
private final char[] b2c;
|
||||
private final boolean isASCIICompatible;
|
||||
private final boolean isLatin1Decodable;
|
||||
|
||||
public Decoder(Charset cs, char[] b2c) {
|
||||
super(cs, 1.0f, 1.0f);
|
||||
this.b2c = b2c;
|
||||
this.isASCIICompatible = false;
|
||||
this.isLatin1Decodable = false;
|
||||
}
|
||||
|
||||
public Decoder(Charset cs, char[] b2c, boolean isASCIICompatible) {
|
||||
super(cs, 1.0f, 1.0f);
|
||||
this.b2c = b2c;
|
||||
this.isASCIICompatible = isASCIICompatible;
|
||||
this.isLatin1Decodable = false;
|
||||
}
|
||||
|
||||
public Decoder(Charset cs, char[] b2c, boolean isASCIICompatible, boolean isLatin1Decodable) {
|
||||
super(cs, 1.0f, 1.0f);
|
||||
this.b2c = b2c;
|
||||
this.isASCIICompatible = isASCIICompatible;
|
||||
this.isLatin1Decodable = isLatin1Decodable;
|
||||
}
|
||||
|
||||
private CoderResult decodeArrayLoop(ByteBuffer src, CharBuffer dst) {
|
||||
|
@ -124,6 +134,18 @@ public class SingleByte
|
|||
repl = newReplacement.charAt(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int decodeToLatin1(byte[] src, int sp, int len, byte[] dst) {
|
||||
if (len > dst.length)
|
||||
len = dst.length;
|
||||
|
||||
int dp = 0;
|
||||
while (dp < len) {
|
||||
dst[dp++] = (byte)decode(src[sp++]);
|
||||
}
|
||||
return dp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int decode(byte[] src, int sp, int len, char[] dst) {
|
||||
if (len > dst.length)
|
||||
|
@ -143,6 +165,11 @@ public class SingleByte
|
|||
public boolean isASCIICompatible() {
|
||||
return isASCIICompatible;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLatin1Decodable() {
|
||||
return isLatin1Decodable;
|
||||
}
|
||||
}
|
||||
|
||||
public static final class Encoder extends CharsetEncoder
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue