Remove dead or unused code

master
Vladimir Hodakov 2019-10-19 01:00:37 +04:00
parent f7b8e36f03
commit 3ab215ed63
Signed by: Vladimir Hodakov
GPG Key ID: 673980B6882F82C6
9 changed files with 12 additions and 163 deletions

View File

@ -198,8 +198,8 @@ func pathMatchOp(q *query, e *Eval, i *Item) queryStateFn {
if len(q.operators)+q.start >= curLocation { if len(q.operators)+q.start >= curLocation {
current, _ := e.location.peek() current, _ := e.location.peek()
nextOp := q.operators[abs(q.loc()-q.start)] nextOp := q.operators[abs(q.loc()-q.start)]
if itemMatchOperator(current, i, nextOp) { if itemMatchOperator(current, nextOp) {
q.pos += 1 q.pos++
if nextOp.whereClauseBytes != nil && len(nextOp.whereClause) > 0 { if nextOp.whereClauseBytes != nil && len(nextOp.whereClause) > 0 {
bucket := exprBucket{ bucket := exprBucket{
@ -312,7 +312,7 @@ func (b *exprBucket) evaluate() (bool, error) {
return res_bool, nil return res_bool, nil
} }
func itemMatchOperator(loc interface{}, i *Item, op *operator) bool { func itemMatchOperator(loc interface{}, op *operator) bool {
topBytes, isKey := loc.([]byte) topBytes, isKey := loc.([]byte)
topInt, isIndex := loc.(int) topInt, isIndex := loc.(int)
if isKey { if isKey {

View File

@ -16,7 +16,6 @@ const (
exprErrorValueNotFound = "Value for %q not found" exprErrorValueNotFound = "Value for %q not found"
exprErrorBadValue = "Bad value %q for type %q" exprErrorBadValue = "Bad value %q for type %q"
exprErrorPathValueNotScalar = "Path value must be scalar value" exprErrorPathValueNotScalar = "Path value must be scalar value"
exprErrorBadOperandType = "Operand type expected to be %q for operation %q"
) )
type exprErrorBadTypeComparison struct { type exprErrorBadTypeComparison struct {

View File

@ -11,7 +11,6 @@ const (
exprNull exprNull
exprString exprString
exprOperators
exprOpEq exprOpEq
exprOpNeq exprOpNeq
exprOpNot exprOpNot
@ -251,7 +250,7 @@ func takeNumeric(l lexer) {
func takePath(l lexer) { func takePath(l lexer) {
inQuotes := false inQuotes := false
var prev int = 0 prev := 0
// capture until end of path - ugly // capture until end of path - ugly
takeLoop: takeLoop:
for { for {
@ -276,12 +275,3 @@ takeLoop:
prev = cur prev = cur
} }
} }
func lexExprEnd(l lexer, state *intStack) stateFn {
cur := l.take()
if cur != eof {
return l.errorf("Expected EOF but received %#U", cur)
}
l.emit(exprEOF)
return nil
}

View File

@ -33,6 +33,7 @@ type lexer interface {
reset() reset()
} }
// nolint:structcheck
type lex struct { type lex struct {
initialState stateFn initialState stateFn
currentStateFn stateFn currentStateFn stateFn
@ -50,33 +51,6 @@ func newLex(initial stateFn) lex {
} }
} }
func (i *Item) clone() *Item {
ic := Item{
typ: i.typ,
pos: i.pos,
val: make([]byte, len(i.val)),
}
copy(ic.val, i.val)
return &ic
}
func itemsDescription(items []Item, nameMap map[int]string) []string {
vals := make([]string, len(items))
for i, item := range items {
vals[i] = itemDescription(&item, nameMap)
}
return vals
}
func itemDescription(item *Item, nameMap map[int]string) string {
var found bool
val, found := nameMap[item.typ]
if !found {
return string(item.val)
}
return val
}
func typesDescription(types []int, nameMap map[int]string) []string { func typesDescription(types []int, nameMap map[int]string) []string {
vals := make([]string, len(types)) vals := make([]string, len(types))
for i, val := range types { for i, val := range types {

View File

@ -3,9 +3,7 @@ package jsonpath
import ( import (
"bytes" "bytes"
"encoding/json" "encoding/json"
"fmt"
"io/ioutil" "io/ioutil"
"math"
"os" "os"
"strings" "strings"
"testing" "testing"
@ -207,21 +205,6 @@ func benchmarkStdUnmarshal(input []byte, b *testing.B) {
} }
} }
func benchmarkStdUnmarshalJSONLarge(b *testing.B) {
input, err := ioutil.ReadFile("large.test")
if err != nil {
b.SkipNow()
}
b.ResetTimer()
for n := 0; n < b.N; n++ {
var x interface{}
err := json.Unmarshal(input, &x)
if err != nil {
b.Error(err)
}
}
}
func BenchmarkStdUnmarshalLarge(b *testing.B) { func BenchmarkStdUnmarshalLarge(b *testing.B) {
input, err := ioutil.ReadFile("large.test") input, err := ioutil.ReadFile("large.test")
if err != nil { if err != nil {
@ -279,31 +262,3 @@ type lexTest struct {
input string input string
tokenTypes []int tokenTypes []int
} }
func i(tokenType int) Item {
return Item{tokenType, 0, []byte{}}
}
func typeIsEqual(i1, i2 []Item, printError bool) bool {
for k := 0; k < int(math.Max(float64(len(i1)), float64(len(i2)))); k++ {
if k < len(i1) {
if i1[k].typ == jsonError && printError {
fmt.Println(string(i1[k].val))
}
} else if k < len(i2) {
if i2[k].typ == jsonError && printError {
fmt.Println(string(i2[k].val))
}
}
if k >= len(i1) || k >= len(i2) {
return false
}
if i1[k].typ != i2[k].typ {
return false
}
}
return true
}

View File

@ -194,15 +194,6 @@ func lexPathIndexRangeSecond(l lexer, state *intStack) stateFn {
} }
} }
func lexPathArrayClose(l lexer, state *intStack) stateFn {
cur := l.take()
if cur != ']' {
return l.errorf("Expected ] instead of %#U", cur)
}
l.emit(pathBracketRight)
return lexPathAfterKey
}
func lexPathAfterValue(l lexer, state *intStack) stateFn { func lexPathAfterValue(l lexer, state *intStack) stateFn {
cur := l.take() cur := l.take()
if cur != eof { if cur != eof {

View File

@ -27,13 +27,14 @@ var optests = []optest{
func TestQueryOperators(t *testing.T) { func TestQueryOperators(t *testing.T) {
as := assert.New(t) as := assert.New(t)
for _, t := range optests { for _, optest := range optests {
path, err := parsePath(t.path) t.Log(optest.name)
path, err := parsePath(optest.path)
as.NoError(err) as.NoError(err)
as.EqualValues(len(t.expected), len(path.operators)) as.EqualValues(len(optest.expected), len(path.operators))
for x, op := range t.expected { for x, op := range optest.expected {
as.EqualValues(pathTokenNames[op], pathTokenNames[path.operators[x].typ]) as.EqualValues(pathTokenNames[op], pathTokenNames[path.operators[x].typ])
} }
} }

View File

@ -15,7 +15,7 @@ func newResults() *Results {
func (q *Results) push(n *Result) { func (q *Results) push(n *Result) {
if q.head == q.tail && q.count > 0 { if q.head == q.tail && q.count > 0 {
nodes := make([]*Result, len(q.nodes)*2, len(q.nodes)*2) nodes := make([]*Result, len(q.nodes)*2)
copy(nodes, q.nodes[q.head:]) copy(nodes, q.nodes[q.head:])
copy(nodes[len(q.nodes)-q.head:], q.nodes[:q.head]) copy(nodes[len(q.nodes)-q.head:], q.nodes[:q.head])
q.head = 0 q.head = 0
@ -37,7 +37,7 @@ func (q *Results) Pop() *Result {
return node return node
} }
func (q *Results) peek() *Result { func (q *Results) Peek() *Result {
if q.count == 0 { if q.count == 0 {
return nil return nil
} }

View File

@ -37,67 +37,6 @@ func (s *intStack) peek() (int, bool) {
return v, true return v, true
} }
func (s *intStack) clone() *intStack {
d := intStack{
values: make([]int, s.len()),
}
copy(d.values, s.values)
return &d
}
func (s *intStack) toArray() []int {
return s.values
}
// Result Stack
type resultStack struct {
values []Result
}
func newResultStack() *resultStack {
return &resultStack{
values: make([]Result, 0),
}
}
func (s *resultStack) len() int {
return len(s.values)
}
func (s *resultStack) push(r Result) {
s.values = append(s.values, r)
}
func (s *resultStack) pop() (Result, bool) {
if s.len() == 0 {
return Result{}, false
}
v, _ := s.peek()
s.values = s.values[:len(s.values)-1]
return v, true
}
func (s *resultStack) peek() (Result, bool) {
if s.len() == 0 {
return Result{}, false
}
v := s.values[len(s.values)-1]
return v, true
}
func (s *resultStack) clone() *resultStack {
d := resultStack{
values: make([]Result, s.len()),
}
copy(d.values, s.values)
return &d
}
func (s *resultStack) toArray() []Result {
return s.values
}
// Interface Stack // Interface Stack
type stack struct { type stack struct {