Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package memory | 5 package memory |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "bytes" | 8 "bytes" |
| 9 "fmt" | 9 "fmt" |
| 10 "sort" | 10 "sort" |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 160 for i, sb := range sortBy[numEqFilts:] { | 160 for i, sb := range sortBy[numEqFilts:] { |
| 161 if q.suffixFormat[i] != sb { | 161 if q.suffixFormat[i] != sb { |
| 162 return false | 162 return false |
| 163 } | 163 } |
| 164 } | 164 } |
| 165 | 165 |
| 166 if id.Builtin() && numEqFilts == 0 { | 166 if id.Builtin() && numEqFilts == 0 { |
| 167 if len(q.eqFilters) > 1 || (len(q.eqFilters) == 1 && q.eqFilters ["__ancestor__"] == nil) { | 167 if len(q.eqFilters) > 1 || (len(q.eqFilters) == 1 && q.eqFilters ["__ancestor__"] == nil) { |
| 168 return false | 168 return false |
| 169 } | 169 } |
| 170 if len(sortBy) > 1 && q.eqFilters["__ancestor__"] != nil { | |
| 171 return false | |
| 172 } | |
| 170 } | 173 } |
| 171 | 174 |
| 172 // Make sure the equalities section doesn't contain any properties we do n't | 175 // Make sure the equalities section doesn't contain any properties we do n't |
| 173 // want in our query. | 176 // want in our query. |
| 174 // | 177 // |
| 175 // numByProp && totalEqFilts will be used to see if this is a perfect ma tch | 178 // numByProp && totalEqFilts will be used to see if this is a perfect ma tch |
| 176 // later. | 179 // later. |
| 177 numByProp := make(map[string]int, len(q.eqFilters)) | 180 numByProp := make(map[string]int, len(q.eqFilters)) |
| 178 totalEqFilts := 0 | 181 totalEqFilts := 0 |
| 179 | 182 |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 380 if len(q.suffixFormat) > 1 { | 383 if len(q.suffixFormat) > 1 { |
| 381 chunks, _ := parseSuffix(q.ns, q.suffixFormat, d ef.start, 1) | 384 chunks, _ := parseSuffix(q.ns, q.suffixFormat, d ef.start, 1) |
| 382 offset = len(chunks[0]) | 385 offset = len(chunks[0]) |
| 383 } | 386 } |
| 384 if !bytes.HasPrefix(def.start[offset:], chopped) { | 387 if !bytes.HasPrefix(def.start[offset:], chopped) { |
| 385 // again, shouldn't happen, but if it does, we w ant to know about it. | 388 // again, shouldn't happen, but if it does, we w ant to know about it. |
| 386 impossible(fmt.Errorf( | 389 impossible(fmt.Errorf( |
| 387 "start suffix for implied ancestor doesn 't start with ancestor! start:%v ancestor:%v", | 390 "start suffix for implied ancestor doesn 't start with ancestor! start:%v ancestor:%v", |
| 388 def.start, chopped)) | 391 def.start, chopped)) |
| 389 } | 392 } |
| 390 » » » def.start = def.start[:offset+len(chopped)] | 393 » » » def.start = def.start[offset+len(chopped):] |
|
Vadim Sh.
2015/09/28 18:52:56
diffs like this look scary.. Was there a bug here?
iannucci
2015/09/29 03:21:37
Yeah there was. I fixed the tests for this too. Ba
| |
| 391 } | 394 } |
| 392 if def.end != nil { | 395 if def.end != nil { |
| 393 offset := 0 | 396 offset := 0 |
| 394 if len(q.suffixFormat) > 1 { | 397 if len(q.suffixFormat) > 1 { |
| 395 chunks, _ := parseSuffix(q.ns, q.suffixFormat, d ef.end, 1) | 398 chunks, _ := parseSuffix(q.ns, q.suffixFormat, d ef.end, 1) |
| 396 offset = len(chunks[0]) | 399 offset = len(chunks[0]) |
| 397 } | 400 } |
| 398 if !bytes.HasPrefix(def.end[offset:], chopped) { | 401 if !bytes.HasPrefix(def.end[offset:], chopped) { |
| 399 impossible(fmt.Errorf( | 402 impossible(fmt.Errorf( |
| 400 "end suffix for implied ancestor doesn't start with ancestor! end:%v ancestor:%v", | 403 "end suffix for implied ancestor doesn't start with ancestor! end:%v ancestor:%v", |
| 401 def.end, chopped)) | 404 def.end, chopped)) |
| 402 } | 405 } |
| 403 » » » def.end = def.end[:offset+len(chopped)] | 406 » » » def.end = def.end[offset+len(chopped):] |
| 404 } | 407 } |
| 405 } | 408 } |
| 406 | 409 |
| 407 return def | 410 return def |
| 408 } | 411 } |
| 409 | 412 |
| 410 type constraints struct { | 413 type constraints struct { |
| 411 constraints map[string][][]byte | 414 constraints map[string][][]byte |
| 412 original map[string][][]byte | 415 original map[string][][]byte |
| 413 residualMapping map[string]int | 416 residualMapping map[string]int |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 546 if bestIdx == nil { | 549 if bestIdx == nil { |
| 547 // something is really wrong here... if relevantIdxs is !nil, then we | 550 // something is really wrong here... if relevantIdxs is !nil, then we |
| 548 // should always be able to make progress in this loop. | 551 // should always be able to make progress in this loop. |
| 549 impossible(fmt.Errorf("deadlock: cannot fulfil query?")) | 552 impossible(fmt.Errorf("deadlock: cannot fulfil query?")) |
| 550 } | 553 } |
| 551 ret = append(ret, generate(q, bestIdx, constraints)) | 554 ret = append(ret, generate(q, bestIdx, constraints)) |
| 552 } | 555 } |
| 553 | 556 |
| 554 return ret, nil | 557 return ret, nil |
| 555 } | 558 } |
| OLD | NEW |