forked from mirror/go-json
Reduce memory usage at compile
This commit is contained in:
parent
e6e344b4e5
commit
06906637f2
|
@ -5,7 +5,7 @@ jobs:
|
|||
name: Test
|
||||
strategy:
|
||||
matrix:
|
||||
os: [ "ubuntu-latest", "macos-latest" ]
|
||||
os: [ "ubuntu-latest", "macos-latest", "windows-latest" ]
|
||||
go-version: [ "1.13", "1.14", "1.15" ]
|
||||
runs-on: ${{ matrix.os }}
|
||||
steps:
|
||||
|
@ -22,7 +22,6 @@ jobs:
|
|||
env:
|
||||
GOGC: 1
|
||||
- name: test with race detector
|
||||
if: ${{ matrix.os == 'macos-latest' }}
|
||||
run: go test -v -race ./ -count=1
|
||||
coverage:
|
||||
name: Coverage
|
||||
|
|
46
encode.go
46
encode.go
|
@ -194,24 +194,21 @@ func (e *Encoder) encode(header *interfaceHeader, isNil bool) ([]byte, error) {
|
|||
typeptr := uintptr(unsafe.Pointer(typ))
|
||||
opcodeMap := loadOpcodeMap()
|
||||
if codeSet, exists := opcodeMap[typeptr]; exists {
|
||||
var code *opcode
|
||||
if e.enabledIndent {
|
||||
if e.enabledHTMLEscape {
|
||||
code = codeSet.escapedCodeIndent
|
||||
} else {
|
||||
code = codeSet.codeIndent
|
||||
}
|
||||
} else {
|
||||
if e.enabledHTMLEscape {
|
||||
code = codeSet.escapedCode
|
||||
} else {
|
||||
code = codeSet.code
|
||||
}
|
||||
}
|
||||
ctx := e.ctx
|
||||
p := uintptr(header.ptr)
|
||||
ctx.init(p, codeSet.codeLength)
|
||||
return e.run(ctx, b, code)
|
||||
|
||||
if e.enabledIndent {
|
||||
if e.enabledHTMLEscape {
|
||||
return e.runEscapedIndent(ctx, b, codeSet.escapedCodeIndent)
|
||||
} else {
|
||||
return e.runIndent(ctx, b, codeSet.codeIndent)
|
||||
}
|
||||
}
|
||||
if e.enabledHTMLEscape {
|
||||
return e.runEscaped(ctx, b, codeSet.escapedCode)
|
||||
}
|
||||
return e.run(ctx, b, codeSet.code)
|
||||
}
|
||||
|
||||
// noescape trick for header.typ ( reflect.*rtype )
|
||||
|
@ -241,26 +238,17 @@ func (e *Encoder) encode(header *interfaceHeader, isNil bool) ([]byte, error) {
|
|||
ctx := e.ctx
|
||||
ctx.init(p, codeLength)
|
||||
|
||||
var c *opcode
|
||||
if e.enabledIndent {
|
||||
if e.enabledHTMLEscape {
|
||||
c = codeSet.escapedCodeIndent
|
||||
return e.runEscapedIndent(ctx, b, codeSet.escapedCodeIndent)
|
||||
} else {
|
||||
c = codeSet.codeIndent
|
||||
}
|
||||
} else {
|
||||
if e.enabledHTMLEscape {
|
||||
c = codeSet.escapedCode
|
||||
} else {
|
||||
c = codeSet.code
|
||||
return e.runIndent(ctx, b, codeSet.codeIndent)
|
||||
}
|
||||
}
|
||||
|
||||
b, err = e.run(ctx, b, c)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
if e.enabledHTMLEscape {
|
||||
return e.runEscaped(ctx, b, codeSet.escapedCode)
|
||||
}
|
||||
return b, nil
|
||||
return e.run(ctx, b, codeSet.code)
|
||||
}
|
||||
|
||||
func encodeFloat32(b []byte, v float32) []byte {
|
||||
|
|
14171
encode_vm.go
14171
encode_vm.go
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue