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

View File

@ -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
return e.runIndent(ctx, b, codeSet.codeIndent)
}
}
} else {
if e.enabledHTMLEscape {
c = codeSet.escapedCode
} else {
c = codeSet.code
return e.runEscaped(ctx, b, codeSet.escapedCode)
}
}
b, err = e.run(ctx, b, c)
if err != nil {
return nil, err
}
return b, nil
return e.run(ctx, b, codeSet.code)
}
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