small bump in performance

This commit is contained in:
Josh Baker 2016-08-21 07:17:11 -07:00
parent 0757a4d1e7
commit cec0cb946f
1 changed files with 25 additions and 7 deletions

View File

@ -208,6 +208,13 @@ func Get(json string, path string) Result {
goto next_part goto next_part
} else if path[i] == '*' || path[i] == '?' { } else if path[i] == '*' || path[i] == '?' {
wild = true wild = true
} else if path[i] == '#' {
arrch = true
if s == i && i+1 < len(path) && path[i+1] == '.' {
alogok = true
alogkey = path[i+2:]
path = path[:i+1]
}
} }
epart = append(epart, path[i]) epart = append(epart, path[i])
} }
@ -279,6 +286,9 @@ read_key:
// must do a nested loop that will look for an isolated // must do a nested loop that will look for an isolated
// double-quote terminator. // double-quote terminator.
for ; i < len(json); i++ { for ; i < len(json); i++ {
if json[i] > '\\' {
continue
}
if json[i] == '"' { if json[i] == '"' {
// a simple string that contains no escape characters. // a simple string that contains no escape characters.
// assign this to the current frame key and we are // assign this to the current frame key and we are
@ -447,6 +457,9 @@ proc_nested:
i++ i++
s2 := i s2 := i
for ; i < len(json); i++ { for ; i < len(json); i++ {
if json[i] > '\\' {
continue
}
if json[i] == '"' { if json[i] == '"' {
// look for an escaped slash // look for an escaped slash
if json[i-1] == '\\' { if json[i-1] == '\\' {
@ -484,16 +497,19 @@ proc_val:
if matched { if matched {
// hit, that's good! // hit, that's good!
if depth == len(parts) { if depth == len(parts) {
value.Raw = json[s:i]
switch vc { switch vc {
case '{', '[': case '{', '[':
value.Type = JSON value.Type = JSON
value.Raw = json[s:i]
case 'n': case 'n':
value.Type = Null value.Type = Null
value.Raw = json[s:i]
case 't': case 't':
value.Type = True value.Type = True
value.Raw = json[s:i]
case 'f': case 'f':
value.Type = False value.Type = False
value.Raw = json[s:i]
case '"': case '"':
value.Type = String value.Type = String
// readstr // readstr
@ -502,14 +518,16 @@ proc_val:
s = i s = i
for ; i < len(json); i++ { for ; i < len(json); i++ {
if json[i] == '"' { if json[i] == '"' {
value.Raw = json[s:i] value.Raw = json[s-1 : i+1]
value.Str = value.Raw value.Str = json[s:i]
i++
break break
} }
if json[i] == '\\' { if json[i] == '\\' {
i++ i++
for ; i < len(json); i++ { for ; i < len(json); i++ {
if json[i] > '\\' {
continue
}
if json[i] == '"' { if json[i] == '"' {
// look for an escaped slash // look for an escaped slash
if json[i-1] == '\\' { if json[i-1] == '\\' {
@ -527,15 +545,15 @@ proc_val:
break break
} }
} }
value.Raw = json[s:i] value.Raw = json[s-1 : i+1]
value.Str = unescape(value.Raw) value.Str = unescape(json[s:i])
i++
break break
} }
} }
// end readstr // end readstr
case '0': case '0':
value.Type = Number value.Type = Number
value.Raw = json[s:i]
value.Num, _ = strconv.ParseFloat(value.Raw, 64) value.Num, _ = strconv.ParseFloat(value.Raw, 64)
} }
return value return value