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
|
name: Test
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
os: [ "ubuntu-latest", "macos-latest" ]
|
os: [ "ubuntu-latest", "macos-latest", "windows-latest" ]
|
||||||
go-version: [ "1.13", "1.14", "1.15" ]
|
go-version: [ "1.13", "1.14", "1.15" ]
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
steps:
|
steps:
|
||||||
|
@ -22,7 +22,6 @@ jobs:
|
||||||
env:
|
env:
|
||||||
GOGC: 1
|
GOGC: 1
|
||||||
- name: test with race detector
|
- name: test with race detector
|
||||||
if: ${{ matrix.os == 'macos-latest' }}
|
|
||||||
run: go test -v -race ./ -count=1
|
run: go test -v -race ./ -count=1
|
||||||
coverage:
|
coverage:
|
||||||
name: 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))
|
typeptr := uintptr(unsafe.Pointer(typ))
|
||||||
opcodeMap := loadOpcodeMap()
|
opcodeMap := loadOpcodeMap()
|
||||||
if codeSet, exists := opcodeMap[typeptr]; exists {
|
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
|
ctx := e.ctx
|
||||||
p := uintptr(header.ptr)
|
p := uintptr(header.ptr)
|
||||||
ctx.init(p, codeSet.codeLength)
|
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 )
|
// 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 := e.ctx
|
||||||
ctx.init(p, codeLength)
|
ctx.init(p, codeLength)
|
||||||
|
|
||||||
var c *opcode
|
|
||||||
if e.enabledIndent {
|
if e.enabledIndent {
|
||||||
if e.enabledHTMLEscape {
|
if e.enabledHTMLEscape {
|
||||||
c = codeSet.escapedCodeIndent
|
return e.runEscapedIndent(ctx, b, codeSet.escapedCodeIndent)
|
||||||
} else {
|
} else {
|
||||||
c = codeSet.codeIndent
|
return e.runIndent(ctx, b, codeSet.codeIndent)
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if e.enabledHTMLEscape {
|
|
||||||
c = codeSet.escapedCode
|
|
||||||
} else {
|
|
||||||
c = codeSet.code
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if e.enabledHTMLEscape {
|
||||||
b, err = e.run(ctx, b, c)
|
return e.runEscaped(ctx, b, codeSet.escapedCode)
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
}
|
||||||
return b, nil
|
return e.run(ctx, b, codeSet.code)
|
||||||
}
|
}
|
||||||
|
|
||||||
func encodeFloat32(b []byte, v float32) []byte {
|
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