mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
json2: improve the performance of encode ~2x (#17050)
This commit is contained in:
parent
630fb2af37
commit
1d51f3109f
@ -236,8 +236,9 @@ fn (e &Encoder) encode_struct[U](val U, level int, mut wr io.Writer) ! {
|
||||
$if field.typ is string {
|
||||
e.encode_string(val.$(field.name).str(), mut wr)!
|
||||
} $else $if field.typ is time.Time {
|
||||
parsed_time := val.$(field.name) as time.Time
|
||||
e.encode_string(parsed_time.format_rfc3339(), mut wr)!
|
||||
wr.write(json2.quote_bytes)!
|
||||
wr.write(val.$(field.name).format_rfc3339().bytes())!
|
||||
wr.write(json2.quote_bytes)!
|
||||
} $else $if field.typ in [bool, $Float, $Int] {
|
||||
wr.write(val.$(field.name).str().bytes())!
|
||||
} $else $if field.is_array {
|
||||
@ -432,6 +433,7 @@ fn (mut iter CharLengthIterator) next() ?int {
|
||||
return len
|
||||
}
|
||||
|
||||
// TODO - Need refactor. Is so slow. The longer the string, the lower the performance.
|
||||
// encode_string returns the JSON spec-compliant version of the string.
|
||||
[manualfree]
|
||||
fn (e &Encoder) encode_string(s string, mut wr io.Writer) ! {
|
||||
|
Loading…
Reference in New Issue
Block a user