minio / simdjson-go

Golang port of simdjson: parsing gigabytes of JSON per second

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

StringCvt() makes unnecessary conversion of integer to string

stokito opened this issue · comments

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.

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

If it's correct, sure.

@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.