@@ -16,7 +16,7 @@ import (
16
16
)
17
17
18
18
type op struct {
19
- k Key
19
+ k * Key
20
20
21
21
pastExists bool
22
22
pastV []byte
@@ -39,14 +39,14 @@ type Key [MapKeyLength]byte
39
39
40
40
// TState defines a struct for storing temporary state.
41
41
type TState struct {
42
- changedKeys map [Key ]* tempStorage
43
- fetchCache map [Key ]* cacheItem // in case we evict and want to re-fetch
42
+ changedKeys map [* Key ]* tempStorage
43
+ fetchCache map [* Key ]* cacheItem // in case we evict and want to re-fetch
44
44
45
45
// We don't differentiate between read and write scope because it is very
46
46
// uncommon for a user to write something without first reading what is
47
47
// there.
48
48
scope [][]byte // stores a list of managed keys in the TState struct
49
- scopeStorage map [Key ][]byte
49
+ scopeStorage map [* Key ][]byte
50
50
51
51
// Ops is a record of all operations performed on [TState]. Tracking
52
52
// operations allows for reverting state to a certain point-in-time.
@@ -57,9 +57,9 @@ type TState struct {
57
57
// maps to have an initial size of [storageSize] and [changedSize] respectively.
58
58
func New (changedSize int ) * TState {
59
59
return & TState {
60
- changedKeys : make (map [Key ]* tempStorage , changedSize ),
60
+ changedKeys : make (map [* Key ]* tempStorage , changedSize ),
61
61
62
- fetchCache : map [Key ]* cacheItem {},
62
+ fetchCache : map [* Key ]* cacheItem {},
63
63
64
64
ops : make ([]* op , 0 , changedSize ),
65
65
}
@@ -79,7 +79,7 @@ func (ts *TState) GetValue(ctx context.Context, key []byte) ([]byte, error) {
79
79
return v , nil
80
80
}
81
81
82
- func (ts * TState ) getValue (_ context.Context , key Key ) ([]byte , bool , bool ) {
82
+ func (ts * TState ) getValue (_ context.Context , key * Key ) ([]byte , bool , bool ) {
83
83
if v , ok := ts .changedKeys [key ]; ok {
84
84
if v .removed {
85
85
return nil , true , false
@@ -97,7 +97,7 @@ func (ts *TState) getValue(_ context.Context, key Key) ([]byte, bool, bool) {
97
97
// FetchAndSetScope then sets the scope of ts to [keys]. If a key exists in
98
98
// ts.fetchCache set the key's value to the value from cache.
99
99
func (ts * TState ) FetchAndSetScope (ctx context.Context , keys [][]byte , db Database ) error {
100
- ts .scopeStorage = map [Key ][]byte {}
100
+ ts .scopeStorage = map [* Key ][]byte {}
101
101
102
102
for _ , key := range keys {
103
103
k := ToStateKeyArray (key )
@@ -123,7 +123,7 @@ func (ts *TState) FetchAndSetScope(ctx context.Context, keys [][]byte, db Databa
123
123
}
124
124
125
125
// SetReadScope sets the readscope of ts to [keys].
126
- func (ts * TState ) SetScope (_ context.Context , keys [][]byte , storage map [Key ][]byte ) {
126
+ func (ts * TState ) SetScope (_ context.Context , keys [][]byte , storage map [* Key ][]byte ) {
127
127
ts .scope = keys
128
128
ts .scopeStorage = storage
129
129
}
@@ -221,22 +221,21 @@ func (ts *TState) WriteChanges(
221
221
defer span .End ()
222
222
223
223
for key , tstorage := range ts .changedKeys {
224
+ k := key [:]
224
225
if ! tstorage .removed {
225
- if err := db .Insert (ctx , key [:] , tstorage .v ); err != nil {
226
+ if err := db .Insert (ctx , k , tstorage .v ); err != nil {
226
227
return err
227
228
}
228
229
continue
229
230
}
230
- if err := db .Remove (ctx , key [:] ); err != nil {
231
+ if err := db .Remove (ctx , k ); err != nil {
231
232
return err
232
233
}
233
234
}
234
235
return nil
235
236
}
236
237
237
238
// ToStateKeyArray converts a byte slice to byte array.
238
- func ToStateKeyArray (key []byte ) Key {
239
- var k Key
240
- copy (k [:], key )
241
- return k
239
+ func ToStateKeyArray (key []byte ) * Key {
240
+ return (* Key )(key )
242
241
}
0 commit comments