Skip to content

Commit 30ccc15

Browse files
committed
Merge remote-tracking branch 'refs/remotes/origin/master' into TablePerfomance
2 parents 2273499 + 702458c commit 30ccc15

2 files changed

Lines changed: 12 additions & 25 deletions

File tree

bql/grammar/llk.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,11 @@ func NewLLk(input string, k int) *LLk {
4545
// appendNextToken tries to append a new token. If not tokens are available
4646
// it appends ItemEOF token.
4747
func appendNextToken(l *LLk) {
48-
i := 0
4948
for t := range l.c {
5049
l.tkns = append(l.tkns, t)
51-
i++
52-
break
53-
}
54-
for ; i < 1; i++ {
55-
l.tkns = append(l.tkns, lexer.Token{
56-
Type: lexer.ItemEOF,
57-
})
50+
return
5851
}
52+
l.tkns = append(l.tkns, lexer.Token{Type: lexer.ItemEOF})
5953
}
6054

6155
// Current returns the current token being processed.

bql/table/table.go

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ func (t *Table) Rows() []Row {
142142
// AddBindings add the new binings provided to the table.
143143
func (t *Table) AddBindings(bs []string) {
144144
for _, b := range bs {
145-
if _, ok := t.mbs[b]; !ok {
145+
if !t.mbs[b] {
146146
t.mbs[b] = true
147147
t.bs = append(t.bs, b)
148148
}
@@ -216,7 +216,7 @@ func equalBindings(b1, b2 map[string]bool) bool {
216216
return false
217217
}
218218
for k := range b1 {
219-
if _, ok := b2[k]; !ok {
219+
if !b2[k] {
220220
return false
221221
}
222222
}
@@ -242,22 +242,15 @@ func (t *Table) AppendTable(t2 *Table) error {
242242
// disjointBinding returns true if they are not overlapping bindings, false
243243
// otherwise.
244244
func disjointBinding(b1, b2 map[string]bool) bool {
245-
m := make(map[string]int)
246245
for k := range b1 {
247-
m[k]++
248-
}
249-
for k := range b2 {
250-
m[k]++
251-
}
252-
for _, cnt := range m {
253-
if cnt != 1 {
246+
if b2[k] {
254247
return false
255248
}
256249
}
257250
return true
258251
}
259252

260-
// MergeRows takes a list of rors and returns a new map containing both.
253+
// MergeRows takes a list of rows and returns a new map containing both.
261254
func MergeRows(ms []Row) Row {
262255
res := make(map[string]*Cell)
263256
for _, om := range ms {
@@ -750,13 +743,13 @@ func (t *Table) Reduce(cfg SortConfig, aaps []AliasAccPair) error {
750743
return nil
751744
}
752745

753-
// Filter removes all the rows were the provided function returns true.
746+
// Filter removes all the rows where the provided function returns true.
754747
func (t *Table) Filter(f func(Row) bool) {
755-
for idx, processed := 0, len(t.data); processed > 0; processed-- {
756-
if f(t.data[idx]) {
757-
t.data = append(t.data[:idx], t.data[idx+1:]...)
758-
idx--
748+
var newData []Row
749+
for _, r := range t.data {
750+
if !f(r) {
751+
newData = append(newData, r)
759752
}
760-
idx++
761753
}
754+
t.data = newData
762755
}

0 commit comments

Comments
 (0)