Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce Memory Usage by Optimizing Order of Fields #101

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions jsonstring.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ var jsonReplacer = newByteReplacer(func() ([]byte, []string) {
}())

type byteReplacer struct {
m [256]byte
newStrings []string
m [256]byte
}

func newByteReplacer(oldChars []byte, newStrings []string) *byteReplacer {
Expand All @@ -79,7 +79,7 @@ func newByteReplacer(oldChars []byte, newStrings []string) *byteReplacer {
m[c] = byte(i)
}
return &byteReplacer{
m: m,
m: m,
newStrings: newStrings,
}
}
Expand Down
15 changes: 8 additions & 7 deletions parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ import (
)

type parser struct {
s *scanner
w io.Writer
packageName string
w io.Writer
s *scanner
packageName string
prefix string
forDepth int
switchDepth int
skipOutputDepth int

skipLineComments bool
prefix string
forDepth int
switchDepth int
skipOutputDepth int

importsUseEmitted bool
packageNameEmitted bool
Expand Down
25 changes: 15 additions & 10 deletions parser/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ func tokenIDToStr(id int) string {
}

type token struct {
ID int
Value []byte

ID int

line int
pos int
}
Expand All @@ -51,25 +52,29 @@ func (t *token) String() string {
}

type scanner struct {
r *bufio.Reader
t token
c byte
err error

r *bufio.Reader

filePath string

line int
lineStr []byte

nextTokenID int

capture bool
capturedValue []byte

t token

line int

nextTokenID int

collapseSpaceDepth int
stripSpaceDepth int
stripToNewLine bool
rewind bool
c byte

capture bool
stripToNewLine bool
rewind bool
}

var tailOfLine = regexp.MustCompile(`^[[:blank:]]*(?:\r*\n)?`)
Expand Down
2 changes: 1 addition & 1 deletion parser/scanner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,6 @@ func testScannerSuccess(t *testing.T, str string, expectedTokens []tt) {
}

type tt struct {
ID int
Value string
ID int
}