| 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 "sync" | 10 "sync" |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 ents := d.mutableEnts(incomplete.Namespace()) | 136 ents := d.mutableEnts(incomplete.Namespace()) |
| 137 | 137 |
| 138 d.Lock() | 138 d.Lock() |
| 139 defer d.Unlock() | 139 defer d.Unlock() |
| 140 return d.allocateIDsLocked(ents, incomplete, n) | 140 return d.allocateIDsLocked(ents, incomplete, n) |
| 141 } | 141 } |
| 142 | 142 |
| 143 func (d *dataStoreData) allocateIDsLocked(ents *memCollection, incomplete *ds.Ke
y, n int) int64 { | 143 func (d *dataStoreData) allocateIDsLocked(ents *memCollection, incomplete *ds.Ke
y, n int) int64 { |
| 144 idKey := []byte(nil) | 144 idKey := []byte(nil) |
| 145 if incomplete.Parent() == nil { | 145 if incomplete.Parent() == nil { |
| 146 » » idKey = rootIDsKey(incomplete.Last().Kind) | 146 » » idKey = rootIDsKey(incomplete.Kind()) |
| 147 } else { | 147 } else { |
| 148 idKey = groupIDsKey(incomplete) | 148 idKey = groupIDsKey(incomplete) |
| 149 } | 149 } |
| 150 return incrementLocked(ents, idKey, n) | 150 return incrementLocked(ents, idKey, n) |
| 151 } | 151 } |
| 152 | 152 |
| 153 func (d *dataStoreData) fixKeyLocked(ents *memCollection, key *ds.Key) *ds.Key { | 153 func (d *dataStoreData) fixKeyLocked(ents *memCollection, key *ds.Key) *ds.Key { |
| 154 if key.Incomplete() { | 154 if key.Incomplete() { |
| 155 id := d.allocateIDsLocked(ents, key, 1) | 155 id := d.allocateIDsLocked(ents, key, 1) |
| 156 » » key = ds.NewKey(key.AppID(), key.Namespace(), key.Last().Kind, "
", id, key.Parent()) | 156 » » key = ds.NewKey(key.AppID(), key.Namespace(), key.Kind(), "", id
, key.Parent()) |
| 157 } | 157 } |
| 158 return key | 158 return key |
| 159 } | 159 } |
| 160 | 160 |
| 161 func (d *dataStoreData) putMulti(keys []*ds.Key, vals []ds.PropertyMap, cb ds.Pu
tMultiCB) { | 161 func (d *dataStoreData) putMulti(keys []*ds.Key, vals []ds.PropertyMap, cb ds.Pu
tMultiCB) { |
| 162 ents := d.mutableEnts(keys[0].Namespace()) | 162 ents := d.mutableEnts(keys[0].Namespace()) |
| 163 | 163 |
| 164 for i, k := range keys { | 164 for i, k := range keys { |
| 165 pmap, _ := vals[i].Save(false) | 165 pmap, _ := vals[i].Save(false) |
| 166 dataBytes := serialize.ToBytes(pmap) | 166 dataBytes := serialize.ToBytes(pmap) |
| (...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 450 | 450 |
| 451 func rpmWoCtx(data []byte, ns string) (ds.PropertyMap, error) { | 451 func rpmWoCtx(data []byte, ns string) (ds.PropertyMap, error) { |
| 452 return serialize.ReadPropertyMap(bytes.NewBuffer(data), | 452 return serialize.ReadPropertyMap(bytes.NewBuffer(data), |
| 453 serialize.WithoutContext, globalAppID, ns) | 453 serialize.WithoutContext, globalAppID, ns) |
| 454 } | 454 } |
| 455 | 455 |
| 456 func rpm(data []byte) (ds.PropertyMap, error) { | 456 func rpm(data []byte) (ds.PropertyMap, error) { |
| 457 return serialize.ReadPropertyMap(bytes.NewBuffer(data), | 457 return serialize.ReadPropertyMap(bytes.NewBuffer(data), |
| 458 serialize.WithContext, "", "") | 458 serialize.WithContext, "", "") |
| 459 } | 459 } |
| OLD | NEW |