mirror of
https://github.com/HDT3213/godis.git
synced 2025-10-05 08:46:56 +08:00
perf: slightly optimize config/config.go
- Exclude the struct tag is space - Exclude configuration file comment, which is starting with space fix: in the case of panic unexpected happened in the method parse0 of parser/parser.go, closing of the channel is needed to prevent the program from getting stuck~ - fine-tune the coding of parser/parser.go Limited ability, hope to make it better~
This commit is contained in:
@@ -76,6 +76,7 @@ func parse0(reader io.Reader, ch chan<- *Payload) {
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
logger.Error(err, string(debug.Stack()))
|
||||
close(ch)
|
||||
}
|
||||
}()
|
||||
|
||||
@@ -88,17 +89,12 @@ func parse0(reader io.Reader, ch chan<- *Payload) {
|
||||
var ioErr bool
|
||||
msg, ioErr, err = readLine(bufReader, &state)
|
||||
if err != nil {
|
||||
ch <- &Payload{Err: err}
|
||||
if ioErr { // encounter io err, stop read
|
||||
ch <- &Payload{
|
||||
Err: err,
|
||||
}
|
||||
close(ch)
|
||||
return
|
||||
}
|
||||
// protocol err, reset read state
|
||||
ch <- &Payload{
|
||||
Err: err,
|
||||
}
|
||||
state = readState{}
|
||||
continue
|
||||
}
|
||||
@@ -227,9 +223,8 @@ func parseMultiBulkHeader(msg []byte, state *readState) error {
|
||||
state.expectedArgsCount = int(expectedLine)
|
||||
state.args = make([][]byte, 0, expectedLine)
|
||||
return nil
|
||||
} else {
|
||||
return errors.New("protocol error: " + string(msg))
|
||||
}
|
||||
return errors.New("protocol error: " + string(msg))
|
||||
}
|
||||
|
||||
func parseBulkHeader(msg []byte, state *readState) error {
|
||||
@@ -246,9 +241,8 @@ func parseBulkHeader(msg []byte, state *readState) error {
|
||||
state.expectedArgsCount = 1
|
||||
state.args = make([][]byte, 0, 1)
|
||||
return nil
|
||||
} else {
|
||||
return errors.New("protocol error: " + string(msg))
|
||||
}
|
||||
return errors.New("protocol error: " + string(msg))
|
||||
}
|
||||
|
||||
func parseSingleLineReply(msg []byte) (redis.Reply, error) {
|
||||
|
Reference in New Issue
Block a user