src/java.base/share/classes/java/lang/StringCoding.java
changeset 58561 3968bf3673c5
parent 51447 8dfed4387312
equal deleted inserted replaced
58560:5a4b4544b810 58561:3968bf3673c5
     1 /*
     1 /*
     2  * Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
   189                                       LATIN1);
   189                                       LATIN1);
   190                 } else {
   190                 } else {
   191                     return result.with(StringLatin1.inflate(ba, off, len), UTF16);
   191                     return result.with(StringLatin1.inflate(ba, off, len), UTF16);
   192                 }
   192                 }
   193             }
   193             }
       
   194             // fastpath for always Latin1 decodable single byte
       
   195             if (COMPACT_STRINGS && cd instanceof ArrayDecoder && ((ArrayDecoder)cd).isLatin1Decodable()) {
       
   196                 byte[] dst = new byte[len];
       
   197                 ((ArrayDecoder)cd).decodeToLatin1(ba, off, len, dst);
       
   198                 return result.with(dst, LATIN1);
       
   199             }
   194             int en = scale(len, cd.maxCharsPerByte());
   200             int en = scale(len, cd.maxCharsPerByte());
   195             char[] ca = new char[en];
   201             char[] ca = new char[en];
   196             if (cd instanceof ArrayDecoder) {
   202             if (cd instanceof ArrayDecoder) {
   197                 int clen = ((ArrayDecoder)cd).decode(ba, off, len, ca);
   203                 int clen = ((ArrayDecoder)cd).decode(ba, off, len, ca);
   198                 return result.with(ca, 0, clen);
   204                 return result.with(ca, 0, clen);
   276         // ascii fastpath
   282         // ascii fastpath
   277         if ((cd instanceof ArrayDecoder) &&
   283         if ((cd instanceof ArrayDecoder) &&
   278             ((ArrayDecoder)cd).isASCIICompatible() && !hasNegatives(ba, off, len)) {
   284             ((ArrayDecoder)cd).isASCIICompatible() && !hasNegatives(ba, off, len)) {
   279             return decodeLatin1(ba, off, len);
   285             return decodeLatin1(ba, off, len);
   280         }
   286         }
       
   287         // fastpath for always Latin1 decodable single byte
       
   288         if (COMPACT_STRINGS && cd instanceof ArrayDecoder && ((ArrayDecoder)cd).isLatin1Decodable()) {
       
   289             byte[] dst = new byte[len];
       
   290             ((ArrayDecoder)cd).decodeToLatin1(ba, off, len, dst);
       
   291             return new Result().with(dst, LATIN1);
       
   292         }
       
   293 
   281         int en = scale(len, cd.maxCharsPerByte());
   294         int en = scale(len, cd.maxCharsPerByte());
   282         if (len == 0) {
   295         if (len == 0) {
   283             return new Result().with();
   296             return new Result().with();
   284         }
   297         }
   285         cd.onMalformedInput(CodingErrorAction.REPLACE)
   298         cd.onMalformedInput(CodingErrorAction.REPLACE)