Remove goto statement

This commit is contained in:
Masaaki Goshima 2020-05-07 13:51:17 +09:00
parent 3574217593
commit ceed634708
2 changed files with 42 additions and 39 deletions

View File

@ -23,13 +23,12 @@ func (d *stringDecoder) decode(buf []byte, cursor int, p uintptr) (int, error) {
}
func (d *stringDecoder) decodeByte(buf []byte, cursor int) ([]byte, int, error) {
LOOP:
for {
switch buf[cursor] {
case '\000':
return nil, 0, errors.New("unexpected error key delimiter")
case ' ', '\n', '\t', '\r':
cursor++
goto LOOP
case '"':
cursor++
start := cursor
@ -64,5 +63,6 @@ LOOP:
cursor += 5
return []byte{'n', 'u', 'l', 'l'}, cursor, nil
}
}
return nil, 0, errors.New("unexpected error key delimiter")
}

View File

@ -27,8 +27,10 @@ func (d *structDecoder) skipValue(buf []byte, cursor int) (int, error) {
braceCount := 0
bracketCount := 0
buflen := len(buf)
for ; cursor < buflen; cursor++ {
for {
switch buf[cursor] {
case '\000':
return cursor, errors.New("unexpected error value")
case '{':
braceCount++
case '[':
@ -59,6 +61,7 @@ func (d *structDecoder) skipValue(buf []byte, cursor int) (int, error) {
}
QUOTE_END:
}
cursor++
}
return cursor, errors.New("unexpected error value")
}