minio / simdjson-go

Golang port of simdjson: parsing gigabytes of JSON per second
Apache License 2.0
1.8k stars 85 forks source link

StringCvt() makes unnecessary conversion of integer to string #44

Closed stokito closed 2 years ago

stokito commented 2 years ago

The StringCvt function contains a code:

    case TagInteger:
        v, err := i.Int()
        return strconv.FormatInt(v, 10), err

That means that internally in the i.Int() the unerlying value will be converted to integer but then immoderately it will be converted back to a string by the strconv.FormatInt(). Can we avoid such double conversion? Will you accept a PR with this?

In my case I expect the int field to be a valid and to be honest I would be just happy to get it as a byte slice. Even for string values I would like to get raw bytes including quotes and then reuse it and write as is into a http response. As far I see I need something like i.tape.stringByteAt(i.cur, i.tape.Tape[i.off]) but not sure if it will work for int fields.

harshavardhana commented 2 years ago

Can we avoid such double conversion? Will you accept a PR with this?

If it's correct, sure.

klauspost commented 2 years ago

@stokito It is already an int, so there is not double conversion.

There is no guarantee you have the original text. Only strings have that guarantee.