Lowering the number of forks required.

This commit is contained in:
Maurice Makaay 2019-07-24 22:42:54 +00:00
parent 68ab1293f2
commit bf7b693cb8
10 changed files with 36 additions and 24 deletions

View File

@ -133,8 +133,8 @@ const (
TypeImplicitTable ValueType = "implicit-table"
)
// SetKeyValuePair is used to set a key and an accompanying value in the
// currently active TOML table of the TOML Document.
// SetKeyValuePair sets a key and an accompanying value in the currently active
// TOML table of the TOML Document.
func (doc *Document) SetKeyValuePair(key Key, value *Value) error {
// First make sure the table structure for storing the value exists.
node, lastKeyPart, err := doc.makeTablePath(key)

View File

@ -1,3 +1,5 @@
PROFILE_COUNT=100
b:
go build
mv burntsushi-tester B
@ -21,20 +23,30 @@ profile: profile-a profile-b
test-a:
numactl --physcpubind=+1 bash -c "time ./A < testfile.toml"
test2-a:
numactl --physcpubind=+1 bash -c "time ./A < testfile2.toml"
profile-a:
numactl --physcpubind=+1 bash -c "./A -p 250 < testfile.toml"
numactl --physcpubind=+1 bash -c "./A -p ${PROFILE_COUNT} < testfile.toml"
test-b:
numactl --physcpubind=+2 bash -c "time ./B < testfile.toml"
test2-b:
numactl --physcpubind=+2 bash -c "time ./B < testfile2.toml"
profile-b:
numactl --physcpubind=+2 bash -c "./B -p 250 < testfile.toml"
numactl --physcpubind=+2 bash -c "./B -p ${PROFILE_COUNT} < testfile.toml"
test-sushi:
numactl --physcpubind=+3 bash -c "time ${GOPATH}/bin/toml-test-decoder < testfile.toml"
test2-sushi:
numactl --physcpubind=+3 bash -c "time ${GOPATH}/bin/toml-test-decoder < testfile2.toml"
test-sushi-a:

View File

@ -48,7 +48,7 @@ func (t *parser) startKeyValuePair(p *parse.API) {
if value, ok := t.parseValue(p); ok {
err := t.doc.SetKeyValuePair(key, value)
if err != nil {
p.Error("%s", err)
p.SetError("%s", err)
} else if !p.Accept(endOfLineOrComment) {
p.Expected("end of line")
}

View File

@ -63,7 +63,7 @@ func (t *parser) parseArray(p *parse.API) (*ast.Value, bool) {
// considered the same type, and so should arrays with different element types).
// This constraint is checked by ast.Array.Append().
if err := a.Append(value); err != nil {
p.Error(err.Error())
p.SetError(err.Error())
return nil, false
}

View File

@ -99,7 +99,7 @@ func (t *parser) parseDateTime(p *parse.API) (*ast.Value, bool) {
}
value, err := time.Parse(layout, p.Result.String())
if err != nil {
p.Error("invalid date/time value %s: %s", p.Result.String(), err)
p.SetError("invalid date/time value %s: %s", p.Result.String(), err)
return nil, false
}

View File

@ -107,6 +107,6 @@ func (t *parser) parseIntegerStartingWithZero(p *parse.API) (*ast.Value, bool) {
if err == nil {
return ast.NewValue(ast.TypeInteger, value), true
}
p.Error("invalid integer value 0%s: %s", p.Result.String(), err)
p.SetError("invalid integer value 0%s: %s", p.Result.String(), err)
return nil, false
}

View File

@ -104,19 +104,19 @@ func (t *parser) parseBasicString(name string, p *parse.API) (string, bool) {
for {
switch {
case p.PeekWithResult(controlCharacter):
p.Error("invalid character in %s: %q (must be escaped)", name, p.Result.Runes[0])
p.SetError("invalid character in %s: %q (must be escaped)", name, p.Result.Runes[0])
return sb.String(), false
case p.Accept(validEscape):
if !appendEscapedRune(p, sb) {
return sb.String(), false
}
case p.Peek(a.Backslash):
p.Error("invalid escape sequence")
p.SetError("invalid escape sequence")
return sb.String(), false
case p.Accept(basicStringDelimiter):
return sb.String(), true
case p.Peek(a.InvalidRune):
p.Error("invalid UTF8 rune")
p.SetError("invalid UTF8 rune")
return sb.String(), false
case p.Accept(a.ValidRune):
sb.WriteString(p.Result.String())
@ -147,10 +147,10 @@ func (t *parser) parseLiteralString(name string, p *parse.API) (string, bool) {
case p.Accept(a.Tab):
sb.WriteString("\t")
case p.PeekWithResult(controlCharacter):
p.Error("invalid character in %s: %q (no control chars allowed, except for tab)", name, p.Result.Runes[0])
p.SetError("invalid character in %s: %q (no control chars allowed, except for tab)", name, p.Result.Runes[0])
return sb.String(), false
case p.Peek(a.InvalidRune):
p.Error("invalid UTF8 rune")
p.SetError("invalid UTF8 rune")
return sb.String(), false
case p.Accept(a.ValidRune):
sb.WriteString(p.Result.String())
@ -195,7 +195,7 @@ func (t *parser) parseMultiLineBasicString(p *parse.API) (string, bool) {
case p.Accept(newline):
sb.WriteString("\n")
case p.PeekWithResult(controlCharacter):
p.Error("invalid character in multi-line basic string: %q (must be escaped)", p.Result.Runes[0])
p.SetError("invalid character in multi-line basic string: %q (must be escaped)", p.Result.Runes[0])
return sb.String(), false
case p.Accept(validEscape):
if !appendEscapedRune(p, sb) {
@ -204,14 +204,14 @@ func (t *parser) parseMultiLineBasicString(p *parse.API) (string, bool) {
case p.Accept(lineEndingBackslash):
// NOOP, the line-ending backslash sequence is skipped.
case p.Peek(a.Backslash):
p.Error("invalid escape sequence")
p.SetError("invalid escape sequence")
return sb.String(), false
case p.Accept(closingMultiLineBasicString):
return sb.String(), true
case p.Accept(a.ValidRune):
sb.WriteString(p.Result.String())
case p.Peek(a.InvalidRune):
p.Error("invalid UTF8 rune")
p.SetError("invalid UTF8 rune")
return sb.String(), false
default:
p.Expected("closing three quotation marks")
@ -243,7 +243,7 @@ func appendEscapedRune(p *parse.API, sb *strings.Builder) bool {
val, _ := strconv.ParseUint(hex, 16, 32) // hex format already validated by parser
r := rune(val)
if !utf8.ValidRune(r) {
p.Error(fmt.Sprintf("invalid UTF8 escape '%s'", s))
p.SetError(fmt.Sprintf("invalid UTF8 escape '%s'", s))
return false
}
sb.WriteRune(r)
@ -279,12 +279,12 @@ func (t *parser) parseMultiLineLiteralString(p *parse.API) (string, bool) {
case p.Accept(newline):
sb.WriteString("\n")
case p.PeekWithResult(controlCharacter):
p.Error("invalid character in literal string: %q (no control chars allowed, except for tab and newline)", p.Result.Runes[0])
p.SetError("invalid character in literal string: %q (no control chars allowed, except for tab and newline)", p.Result.Runes[0])
return sb.String(), false
case p.Accept(a.ValidRune):
sb.WriteString(p.Result.String())
case p.Peek(a.InvalidRune):
p.Error("invalid UTF8 rune")
p.SetError("invalid UTF8 rune")
return sb.String(), false
default:
p.Expected("closing three single quotes")

View File

@ -80,7 +80,7 @@ func (t *parser) startArrayOfTables(p *parse.API) {
return
}
if err := t.doc.OpenArrayOfTables(key); err != nil {
p.Error("%s", err)
p.SetError("%s", err)
return
}
p.Handle(t.startDocument)
@ -136,7 +136,7 @@ func (t *parser) startPlainTable(p *parse.API) {
return
}
if err := t.doc.OpenTable(key); err != nil {
p.Error("%s", err)
p.SetError("%s", err)
return
}
p.Handle(t.startDocument)
@ -188,7 +188,7 @@ func (t *parser) parseInlineTable(p *parse.API) (*ast.Value, bool) {
}
err := subdoc.doc.SetKeyValuePair(key, value)
if err != nil {
p.Error("%s", err)
p.SetError("%s", err)
return nil, false
}

View File

@ -6,7 +6,7 @@ FILE=normal.toml
ITER=10000
cd ../cmd/burntsushi-tester
go build
go build -gcflags=all=-l
cd ../../parse2
ppfile=`cat $FILE | ../cmd/burntsushi-tester/burntsushi-tester -p $ITER 2>&1 | grep "profiling enabled" | cut -d, -f2`
go tool pprof -http 0.0.0.0:8888 ../cmd/burntsushi-tester/burntsushi-tester $ppfile

View File

@ -11,6 +11,6 @@
#go build -gcflags=all=-l -v
go build -v
ppfile=`cat long.toml | ./parse2 -p 25 2>&1 | grep "profiling enabled" | cut -d, -f2`
ppfile=`cat long.toml | ./parse2 -p 50 2>&1 | grep "profiling enabled" | cut -d, -f2`
go tool pprof -http 0.0.0.0:8888 ./parse2 $ppfile