bytedance / sonic

A blazingly fast JSON serializing & deserializing library
Apache License 2.0
6.59k stars 327 forks source link

How to make the unmarshaling process of json int array faster? #572

Open kuaikuai opened 6 months ago

kuaikuai commented 6 months ago

sonic

code as the flow: `func UnmarshalIntVector(size int, data string) ([]int32, error) { if size < 0 { return parseInt32(data) } var out []int32 if size > 0 { out = make([]int32, 0, size) } err := sonic.UnmarshalString(data, &out) if err != nil { return nil, fmt.Errorf("UnmarshalIntVector json error: %s", err.Error()) }

if size == 0 {
    return out, nil
}
length := len(out)
if size != length {
    return nil, fmt.Errorf("UnmarshalIntVector needed size %d != len %d", size, length)
}

return out, nil

}`

AsterDY commented 6 months ago

Didn't get what you mean. give more explaination