mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-09-07 00:24:17 +08:00
- Added `GetGJSONBytesNoCopy` in `internal/util` for safe, no-copy JSON parse operations leveraging `unsafe`. - Replaced `gjson.GetBytes` with the new helper in key payload processing paths (`kimi_executor`, `vertex_payload_helpers`, etc.) to improve performance. - Added unit tests for behavior validation, including edge cases with empty input.
17 lines
404 B
Go
17 lines
404 B
Go
package util
|
|
|
|
import (
|
|
"unsafe"
|
|
|
|
"github.com/tidwall/gjson"
|
|
)
|
|
|
|
// GetGJSONBytesNoCopy returns a GJSON result that may reference data directly.
|
|
// Callers must not retain the result or mutate data while using it.
|
|
func GetGJSONBytesNoCopy(data []byte, path string) gjson.Result {
|
|
if len(data) == 0 {
|
|
return gjson.Result{}
|
|
}
|
|
return gjson.Get(unsafe.String(unsafe.SliceData(data), len(data)), path)
|
|
}
|