Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(69)

Side by Side Diff: impl/memory/gkvlite_iter.go

Issue 1365743002: Refactor serialization helpers from impl/memory -> service/datastore/serialize (Closed) Base URL: https://github.com/luci/gae.git@estimate_size
Patch Set: fix comments Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « impl/memory/datastore_query_test.go ('k') | impl/memory/gkvlite_iter_test.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "sync" 9 "sync"
10 10
11 "github.com/luci/gae/service/datastore/serialize"
11 "github.com/luci/gkvlite" 12 "github.com/luci/gkvlite"
12 ) 13 )
13 14
14 type iterDefinition struct { 15 type iterDefinition struct {
15 // The collection to iterate over 16 // The collection to iterate over
16 c *memCollection 17 c *memCollection
17 18
18 // The prefix to always assert for every row. A nil prefix matches every row. 19 // The prefix to always assert for every row. A nil prefix matches every row.
19 prefix []byte 20 prefix []byte
20 21
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 for { 58 for {
58 stop := false 59 stop := false
59 restart := false 60 restart := false
60 61
61 for idx, it := range ts { 62 for idx, it := range ts {
62 if skip >= 0 && skip == idx { 63 if skip >= 0 && skip == idx {
63 continue 64 continue
64 } 65 }
65 def := defs[idx] 66 def := defs[idx]
66 67
67 » » » it.next(bjoin(def.prefix, suffix), func(itm *gkvlite.Ite m) { 68 » » » it.next(serialize.Join(def.prefix, suffix), func(itm *gk vlite.Item) {
68 if itm == nil { 69 if itm == nil {
69 // we hit the end of an iterator, we're now done with the whole 70 // we hit the end of an iterator, we're now done with the whole
70 // query. 71 // query.
71 stop = true 72 stop = true
72 return 73 return
73 } 74 }
74 75
75 sfxRO := itm.Key[prefixLens[idx]:] 76 sfxRO := itm.Key[prefixLens[idx]:]
76 77
77 if bytes.Compare(sfxRO, suffix) > 0 { 78 if bytes.Compare(sfxRO, suffix) > 0 {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 cmdChan := make(chan *cmd) 121 cmdChan := make(chan *cmd)
121 ret := &iterator{ 122 ret := &iterator{
122 ch: cmdChan, 123 ch: cmdChan,
123 } 124 }
124 125
125 prefix := def.prefix 126 prefix := def.prefix
126 collection := def.c 127 collection := def.c
127 128
128 // convert the suffixes from the iterDefinition into full rows for the 129 // convert the suffixes from the iterDefinition into full rows for the
129 // underlying storage. 130 // underlying storage.
130 » start := bjoin(prefix, def.start) 131 » start := serialize.Join(prefix, def.start)
131 132
132 end := []byte(nil) 133 end := []byte(nil)
133 if def.end != nil { 134 if def.end != nil {
134 » » end = bjoin(prefix, def.end) 135 » » end = serialize.Join(prefix, def.end)
135 } 136 }
136 137
137 go func() { 138 go func() {
138 c := (*cmd)(nil) 139 c := (*cmd)(nil)
139 ensureCmd := func() bool { 140 ensureCmd := func() bool {
140 if c == nil { 141 if c == nil {
141 c = <-cmdChan 142 c = <-cmdChan
142 if c == nil { // stop() 143 if c == nil { // stop()
143 return false 144 return false
144 } 145 }
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 t.ch <- &cmd{targ, func(i *gkvlite.Item) { 206 t.ch <- &cmd{targ, func(i *gkvlite.Item) {
206 defer close(waiter) 207 defer close(waiter)
207 208
208 if i == nil { 209 if i == nil {
209 t.stop() 210 t.stop()
210 } 211 }
211 cb(i) 212 cb(i)
212 }} 213 }}
213 <-waiter 214 <-waiter
214 } 215 }
OLDNEW
« no previous file with comments | « impl/memory/datastore_query_test.go ('k') | impl/memory/gkvlite_iter_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698