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)
|
// Default configuration values (matching lua-cjson defaults)
|
||||||
const (
|
const (
|
||||||
defaultEncodeSparseConvert = false
|
defaultEncodeSparseConvert = false
|
||||||
defaultEncodeSparseRatio = 2
|
defaultEncodeSparseRatio = 2
|
||||||
defaultEncodeSparseSafe = 10
|
defaultEncodeSparseSafe = 10
|
||||||
defaultEncodeMaxDepth = 1000
|
defaultEncodeMaxDepth = 1000
|
||||||
defaultDecodeMaxDepth = 1000
|
defaultDecodeMaxDepth = 1000
|
||||||
defaultEncodeNumberPrecision = 14
|
defaultEncodeNumberPrecision = 14
|
||||||
defaultEncodeKeepBuffer = true
|
defaultEncodeKeepBuffer = true
|
||||||
defaultEncodeSortKeys = false // 默认不排序,保持高性能
|
defaultEncodeSortKeys = false // 默认不排序,保持高性能
|
||||||
)
|
)
|
||||||
|
|
||||||
// sparseArrayConfig controls sparse array handling during encoding.
|
// sparseArrayConfig controls sparse array handling during encoding.
|
||||||
@ -21,12 +21,12 @@ type sparseArrayConfig struct {
|
|||||||
|
|
||||||
// Config holds all configuration options for a GJSON instance.
|
// Config holds all configuration options for a GJSON instance.
|
||||||
type Config struct {
|
type Config struct {
|
||||||
encodeSparseArray sparseArrayConfig
|
encodeSparseArray sparseArrayConfig
|
||||||
encodeMaxDepth int
|
encodeMaxDepth int
|
||||||
decodeMaxDepth int
|
decodeMaxDepth int
|
||||||
encodeNumberPrecision int
|
encodeNumberPrecision int
|
||||||
encodeKeepBuffer bool
|
encodeKeepBuffer bool
|
||||||
encodeSortKeys bool // 是否对 object 键排序(稳定输出)
|
encodeSortKeys bool // 是否对 object 键排序(稳定输出)
|
||||||
}
|
}
|
||||||
|
|
||||||
// defaultConfig returns a new Config with default values.
|
// defaultConfig returns a new Config with default values.
|
||||||
@ -37,11 +37,11 @@ func defaultConfig() *Config {
|
|||||||
ratio: defaultEncodeSparseRatio,
|
ratio: defaultEncodeSparseRatio,
|
||||||
safe: defaultEncodeSparseSafe,
|
safe: defaultEncodeSparseSafe,
|
||||||
},
|
},
|
||||||
encodeMaxDepth: defaultEncodeMaxDepth,
|
encodeMaxDepth: defaultEncodeMaxDepth,
|
||||||
decodeMaxDepth: defaultDecodeMaxDepth,
|
decodeMaxDepth: defaultDecodeMaxDepth,
|
||||||
encodeNumberPrecision: defaultEncodeNumberPrecision,
|
encodeNumberPrecision: defaultEncodeNumberPrecision,
|
||||||
encodeKeepBuffer: defaultEncodeKeepBuffer,
|
encodeKeepBuffer: defaultEncodeKeepBuffer,
|
||||||
encodeSortKeys: defaultEncodeSortKeys,
|
encodeSortKeys: defaultEncodeSortKeys,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -53,10 +53,10 @@ func (c *Config) Clone() *Config {
|
|||||||
ratio: c.encodeSparseArray.ratio,
|
ratio: c.encodeSparseArray.ratio,
|
||||||
safe: c.encodeSparseArray.safe,
|
safe: c.encodeSparseArray.safe,
|
||||||
},
|
},
|
||||||
encodeMaxDepth: c.encodeMaxDepth,
|
encodeMaxDepth: c.encodeMaxDepth,
|
||||||
decodeMaxDepth: c.decodeMaxDepth,
|
decodeMaxDepth: c.decodeMaxDepth,
|
||||||
encodeNumberPrecision: c.encodeNumberPrecision,
|
encodeNumberPrecision: c.encodeNumberPrecision,
|
||||||
encodeKeepBuffer: c.encodeKeepBuffer,
|
encodeKeepBuffer: c.encodeKeepBuffer,
|
||||||
encodeSortKeys: c.encodeSortKeys,
|
encodeSortKeys: c.encodeSortKeys,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -267,4 +267,3 @@ func formatNumber(n float64, precision int) string {
|
|||||||
// Use 'g' format for floating point
|
// Use 'g' format for floating point
|
||||||
return strconv.FormatFloat(n, 'g', precision, 64)
|
return strconv.FormatFloat(n, 'g', precision, 64)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -368,7 +368,6 @@ func (c *LuaCoroutine) executeProto(proto *glua.FunctionProto) error {
|
|||||||
fn := c.Co.NewFunctionFromProto(proto)
|
fn := c.Co.NewFunctionFromProto(proto)
|
||||||
c.Co.Push(fn)
|
c.Co.Push(fn)
|
||||||
err := c.Co.PCall(0, 0, nil)
|
err := c.Co.PCall(0, 0, nil)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
atomic.AddUint64(&c.Engine.stats.ScriptsErrors, 1)
|
atomic.AddUint64(&c.Engine.stats.ScriptsErrors, 1)
|
||||||
return fmt.Errorf("lua execution error: %w", err)
|
return fmt.Errorf("lua execution error: %w", err)
|
||||||
|
|||||||
@ -50,7 +50,7 @@ func NewLStatePool(factory func() *glua.LState, initialSize, maxSize int) *LStat
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 预热:预先创建 initialSize 个 LState
|
// 预热:预先创建 initialSize 个 LState
|
||||||
for i := 0; i < initialSize; i++ {
|
for range initialSize {
|
||||||
L := p.factory()
|
L := p.factory()
|
||||||
p.pool = append(p.pool, L)
|
p.pool = append(p.pool, L)
|
||||||
p.current++
|
p.current++
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user