gcodeforks / json-smart

Automatically exported from code.google.com/p/json-smart
0 stars 0 forks source link

Can add a method in JSONValue defined as follows: #27

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Can add a method in JSONValue defined as follows:

public static Object parse(byte[] in, int beginIndex, int endIndex);

    beginIndex - the beginning index, inclusive.
    endIndex - the ending index, exclusive. 

It can brings great performance improvements for my program.

Original issue reported on code.google.com by runner....@gmail.com on 11 May 2012 at 2:13

GoogleCodeExporter commented 9 years ago
try that:

byte[] bytes;
String charset = "ANSI";
JSONValue.parse(new String(bytes, beginIndex, endIndex, charset));

the performance improvement should be the same due to Json-smart internal 
String optimisations.

Original comment by uriel.chemouni on 11 May 2012 at 4:25

GoogleCodeExporter commented 9 years ago
This is not the same, new String () will cause the bytes to be copied, 
definitions of detailed below:

    public String(byte bytes[], int offset, int length, String charsetName)
    throws UnsupportedEncodingException
    {
    if (charsetName == null)
        throw new NullPointerException("charsetName");
    checkBounds(bytes, offset, length);
    char[] v = StringCoding.decode(charsetName, bytes, offset, length);
    this.offset = 0;
    this.count = v.length;
    this.value = v;
    }

The size of the bytes in my program more than 10k bytes, so it's a great 
influence on my program

Original comment by runner....@gmail.com on 14 May 2012 at 2:07

GoogleCodeExporter commented 9 years ago
so ...
you're right.

Original comment by uriel.chemouni on 23 Jun 2012 at 4:32

GoogleCodeExporter commented 9 years ago
public Object parse(byte[] in, int offset, int length);

is now avaiable in Json-smart V1

build json-smart from git, or wait for V 1.1.2

Original comment by uriel.chemouni on 23 Jun 2012 at 4:53