2
0
Fork 0
mirror of https://github.com/ii64/sonic.git synced 2026-06-21 00:46:43 +08:00

optimize type assertion (#324)

This commit is contained in:
linuxsong 2022-10-31 12:47:12 +08:00 committed by GitHub
parent 78c2ade913
commit 2866800519
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 6 deletions

View file

@ -695,14 +695,14 @@ func (self *Node) GetByPath(path ...interface{}) *Node {
} }
var s = self var s = self
for _, p := range path { for _, p := range path {
switch p.(type) { switch p := p.(type) {
case int: case int:
s = s.Index(p.(int)) s = s.Index(p)
if !s.Valid() { if !s.Valid() {
return s return s
} }
case string: case string:
s = s.Get(p.(string)) s = s.Get(p)
if !s.Valid() { if !s.Valid() {
return s return s
} }

View file

@ -40,13 +40,13 @@ func (self *Searcher) GetByPath(path ...interface{}) (Node, error) {
var err types.ParsingError var err types.ParsingError
for _, p := range path { for _, p := range path {
switch p.(type) { switch p := p.(type) {
case int: case int:
if err = self.parser.searchIndex(p.(int)); err != 0 { if err = self.parser.searchIndex(p); err != 0 {
return Node{}, self.parser.ExportError(err) return Node{}, self.parser.ExportError(err)
} }
case string: case string:
if err = self.parser.searchKey(p.(string)); err != 0 { if err = self.parser.searchKey(p); err != 0 {
return Node{}, self.parser.ExportError(err) return Node{}, self.parser.ExportError(err)
} }
default: default: