style: format code and modernize loop syntax
- Align struct fields and constants in gjson/config.go - Add missing newline at EOF in gjson/decode.go - Remove trailing blank line in gjson/encode.go - Remove extra blank line in internal/lua/coroutine.go - Use modern for range syntax in internal/lua/pool.go Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
parent
8643a0aff9
commit
c37364b309
@ -2,14 +2,14 @@ package gjson
|
||||
|
||||
// Default configuration values (matching lua-cjson defaults)
|
||||
const (
|
||||
defaultEncodeSparseConvert = false
|
||||
defaultEncodeSparseRatio = 2
|
||||
defaultEncodeSparseSafe = 10
|
||||
defaultEncodeMaxDepth = 1000
|
||||
defaultDecodeMaxDepth = 1000
|
||||
defaultEncodeSparseConvert = false
|
||||
defaultEncodeSparseRatio = 2
|
||||
defaultEncodeSparseSafe = 10
|
||||
defaultEncodeMaxDepth = 1000
|
||||
defaultDecodeMaxDepth = 1000
|
||||
defaultEncodeNumberPrecision = 14
|
||||
defaultEncodeKeepBuffer = true
|
||||
defaultEncodeSortKeys = false // 默认不排序,保持高性能
|
||||
defaultEncodeKeepBuffer = true
|
||||
defaultEncodeSortKeys = false // 默认不排序,保持高性能
|
||||
)
|
||||
|
||||
// sparseArrayConfig controls sparse array handling during encoding.
|
||||
@ -21,12 +21,12 @@ type sparseArrayConfig struct {
|
||||
|
||||
// Config holds all configuration options for a GJSON instance.
|
||||
type Config struct {
|
||||
encodeSparseArray sparseArrayConfig
|
||||
encodeMaxDepth int
|
||||
decodeMaxDepth int
|
||||
encodeSparseArray sparseArrayConfig
|
||||
encodeMaxDepth int
|
||||
decodeMaxDepth int
|
||||
encodeNumberPrecision int
|
||||
encodeKeepBuffer bool
|
||||
encodeSortKeys bool // 是否对 object 键排序(稳定输出)
|
||||
encodeKeepBuffer bool
|
||||
encodeSortKeys bool // 是否对 object 键排序(稳定输出)
|
||||
}
|
||||
|
||||
// defaultConfig returns a new Config with default values.
|
||||
@ -37,11 +37,11 @@ func defaultConfig() *Config {
|
||||
ratio: defaultEncodeSparseRatio,
|
||||
safe: defaultEncodeSparseSafe,
|
||||
},
|
||||
encodeMaxDepth: defaultEncodeMaxDepth,
|
||||
decodeMaxDepth: defaultDecodeMaxDepth,
|
||||
encodeMaxDepth: defaultEncodeMaxDepth,
|
||||
decodeMaxDepth: defaultDecodeMaxDepth,
|
||||
encodeNumberPrecision: defaultEncodeNumberPrecision,
|
||||
encodeKeepBuffer: defaultEncodeKeepBuffer,
|
||||
encodeSortKeys: defaultEncodeSortKeys,
|
||||
encodeKeepBuffer: defaultEncodeKeepBuffer,
|
||||
encodeSortKeys: defaultEncodeSortKeys,
|
||||
}
|
||||
}
|
||||
|
||||
@ -53,10 +53,10 @@ func (c *Config) Clone() *Config {
|
||||
ratio: c.encodeSparseArray.ratio,
|
||||
safe: c.encodeSparseArray.safe,
|
||||
},
|
||||
encodeMaxDepth: c.encodeMaxDepth,
|
||||
decodeMaxDepth: c.decodeMaxDepth,
|
||||
encodeMaxDepth: c.encodeMaxDepth,
|
||||
decodeMaxDepth: c.decodeMaxDepth,
|
||||
encodeNumberPrecision: c.encodeNumberPrecision,
|
||||
encodeKeepBuffer: c.encodeKeepBuffer,
|
||||
encodeSortKeys: c.encodeSortKeys,
|
||||
encodeKeepBuffer: c.encodeKeepBuffer,
|
||||
encodeSortKeys: c.encodeSortKeys,
|
||||
}
|
||||
}
|
||||
|
||||
@ -108,4 +108,4 @@ func parseJSONNumber(s string) (glua.LNumber, error) {
|
||||
}
|
||||
|
||||
return glua.LNumber(0), fmt.Errorf("invalid number format: %s", s)
|
||||
}
|
||||
}
|
||||
|
||||
@ -267,4 +267,3 @@ func formatNumber(n float64, precision int) string {
|
||||
// Use 'g' format for floating point
|
||||
return strconv.FormatFloat(n, 'g', precision, 64)
|
||||
}
|
||||
|
||||
|
||||
@ -368,7 +368,6 @@ func (c *LuaCoroutine) executeProto(proto *glua.FunctionProto) error {
|
||||
fn := c.Co.NewFunctionFromProto(proto)
|
||||
c.Co.Push(fn)
|
||||
err := c.Co.PCall(0, 0, nil)
|
||||
|
||||
if err != nil {
|
||||
atomic.AddUint64(&c.Engine.stats.ScriptsErrors, 1)
|
||||
return fmt.Errorf("lua execution error: %w", err)
|
||||
|
||||
@ -50,7 +50,7 @@ func NewLStatePool(factory func() *glua.LState, initialSize, maxSize int) *LStat
|
||||
}
|
||||
|
||||
// 预热:预先创建 initialSize 个 LState
|
||||
for i := 0; i < initialSize; i++ {
|
||||
for range initialSize {
|
||||
L := p.factory()
|
||||
p.pool = append(p.pool, L)
|
||||
p.current++
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user