Re: ClassReader.readUtf and compact strings

"Eric Bruneton" (via asm Mailing List) <[email protected]> Sat, 6 Feb 2021 11:50:48 +0100
Newsgroups gmane.comp.java.objectweb.asm
Message-ID <[email protected]>
This is a multi-part message in MIME format...

------------=_1612608651-15976-7
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Language: en-US
Content-Transfer-Encoding: 8bit

Thanks for your experiments! The String constructor using a Charset is 
only available in JDK 1.6, and we maintain 1.5 compatibility currently, 
so we can't use it.

Le 06/02/2021 à 11:42, Eirik Bjørsnøs (via asm Mailing List) a écrit :
>     I imagine there could be a performance win of not doing this byte[]
>     -> char[] -> byte[] dance, given that most class strings are ASCII
>     anyway.
> 
> 
> I did a quick implementation of this and could not observe any 
> performance difference. Probably the JIT optimizes much of this away, or 
> the cost of array copying is dominating.
> 
> The change did remove some crufty code though, which might be a win, if 
> only in terms of readability / maintainability.
> 
> Cheers,
> Eirik.
> 
> 
> class FastClassReader extends ClassReader {
> 
>      public FastClassReader(byte[] classfileBuffer) {
>          super(classfileBuffer);
>      }
> 
>      @Override
>      public final String readUTF8(int offset, char[] charBuffer) {
>          int constantPoolEntryIndex = readUnsignedShort(offset);
>          if (offset == 0 || constantPoolEntryIndex == 0) {
>              return null;
>          }
>          return fastReadUtf(constantPoolEntryIndex);
>      }
> 
>      private String fastReadUtf(final int constantPoolEntryIndex) {
>          String value = constantUtf8Values[constantPoolEntryIndex];
>          if (value != null) {
>              return value;
>          }
>          return fastReadString(constantPoolEntryIndex);
>      }
> 
>      private String fastReadString(int constantPoolEntryIndex) {
>          int cpInfoOffset = getItem(constantPoolEntryIndex);
>          return constantUtf8Values[constantPoolEntryIndex] =
>                  new String(classFileBuffer, cpInfoOffset + 2, 
> readUnsignedShort(cpInfoOffset), StandardCharsets.UTF_8);
>      }
> 
> }
> 
> 
> 

------------=_1612608651-15976-7
Content-Type: text/plain; charset="UTF-8"
Content-Disposition: inline
Content-Transfer-Encoding: 8bit


-- 
You receive this message as a subscriber of the [email protected] mailing list.
To unsubscribe: mailto:[email protected]
For general help: mailto:[email protected]?subject=help
OW2 mailing lists service home page: http://www.ow2.org/wws

------------=_1612608651-15976-7--