Reduce memory usage at compile

This commit is contained in:
Masaaki Goshima 2021-01-11 05:16:37 +09:00
parent e6e344b4e5
commit 06906637f2
6 changed files with 15442 additions and 14190 deletions

View File

@ -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

View File

@ -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 { if e.enabledHTMLEscape {
c = codeSet.escapedCode return e.runEscaped(ctx, b, codeSet.escapedCode)
} else {
c = codeSet.code
} }
} return e.run(ctx, b, codeSet.code)
b, err = e.run(ctx, b, c)
if err != nil {
return nil, err
}
return b, nil
} }
func encodeFloat32(b []byte, v float32) []byte { func encodeFloat32(b []byte, v float32) []byte {

14171
encode_vm.go

File diff suppressed because it is too large Load Diff

5709
encode_vm_escaped.go Normal file

File diff suppressed because it is too large Load Diff

4852
encode_vm_escaped_indent.go Normal file

File diff suppressed because it is too large Load Diff

4851
encode_vm_indent.go Normal file

File diff suppressed because it is too large Load Diff