@@ -15,7 +15,7 @@ import (
15
15
)
16
16
17
17
type op struct {
18
- k string
18
+ k [] byte
19
19
20
20
pastExists bool
21
21
pastV []byte
@@ -67,22 +67,21 @@ func (ts *TState) GetValue(ctx context.Context, key []byte) ([]byte, error) {
67
67
if ! ts .checkScope (ctx , key ) {
68
68
return nil , ErrKeyNotSpecified
69
69
}
70
- k := string (key )
71
- v , _ , exists := ts .getValue (ctx , k )
70
+ v , _ , exists := ts .getValue (ctx , key )
72
71
if ! exists {
73
72
return nil , database .ErrNotFound
74
73
}
75
74
return v , nil
76
75
}
77
76
78
- func (ts * TState ) getValue (_ context.Context , key string ) ([]byte , bool , bool ) {
79
- if v , ok := ts .changedKeys [key ]; ok {
77
+ func (ts * TState ) getValue (_ context.Context , key [] byte ) ([]byte , bool , bool ) {
78
+ if v , ok := ts .changedKeys [string ( key ) ]; ok {
80
79
if v .removed {
81
80
return nil , true , false
82
81
}
83
82
return v .v , true , true
84
83
}
85
- v , ok := ts .scopeStorage [key ]
84
+ v , ok := ts .scopeStorage [string ( key ) ]
86
85
if ! ok {
87
86
return nil , false , false
88
87
}
@@ -95,23 +94,22 @@ func (ts *TState) getValue(_ context.Context, key string) ([]byte, bool, bool) {
95
94
func (ts * TState ) FetchAndSetScope (ctx context.Context , keys [][]byte , db Database ) error {
96
95
ts .scopeStorage = map [string ][]byte {}
97
96
for _ , key := range keys {
98
- k := string (key )
99
- if val , ok := ts .fetchCache [k ]; ok {
97
+ if val , ok := ts .fetchCache [string (key )]; ok {
100
98
if val .Exists {
101
- ts .scopeStorage [k ] = val .Value
99
+ ts .scopeStorage [string ( key ) ] = val .Value
102
100
}
103
101
continue
104
102
}
105
103
v , err := db .GetValue (ctx , key )
106
104
if errors .Is (err , database .ErrNotFound ) {
107
- ts .fetchCache [k ] = & cacheItem {Exists : false }
105
+ ts .fetchCache [string ( key ) ] = & cacheItem {Exists : false }
108
106
continue
109
107
}
110
108
if err != nil {
111
109
return err
112
110
}
113
- ts .fetchCache [k ] = & cacheItem {Value : v , Exists : true }
114
- ts .scopeStorage [k ] = v
111
+ ts .fetchCache [string ( key ) ] = & cacheItem {Value : v , Exists : true }
112
+ ts .scopeStorage [string ( key ) ] = v
115
113
}
116
114
ts .scope = keys
117
115
return nil
@@ -139,15 +137,14 @@ func (ts *TState) Insert(ctx context.Context, key []byte, value []byte) error {
139
137
if ! ts .checkScope (ctx , key ) {
140
138
return ErrKeyNotSpecified
141
139
}
142
- k := string (key )
143
- past , changed , exists := ts .getValue (ctx , k )
140
+ past , changed , exists := ts .getValue (ctx , key )
144
141
ts .ops = append (ts .ops , & op {
145
- k : k ,
142
+ k : key ,
146
143
pastExists : exists ,
147
144
pastV : past ,
148
145
pastChanged : changed ,
149
146
})
150
- ts .changedKeys [k ] = & tempStorage {value , false }
147
+ ts .changedKeys [string ( key ) ] = & tempStorage {value , false }
151
148
return nil
152
149
}
153
150
@@ -156,18 +153,17 @@ func (ts *TState) Remove(ctx context.Context, key []byte) error {
156
153
if ! ts .checkScope (ctx , key ) {
157
154
return ErrKeyNotSpecified
158
155
}
159
- k := string (key )
160
- past , changed , exists := ts .getValue (ctx , k )
156
+ past , changed , exists := ts .getValue (ctx , key )
161
157
if ! exists {
162
158
return nil
163
159
}
164
160
ts .ops = append (ts .ops , & op {
165
- k : k ,
161
+ k : key ,
166
162
pastExists : true ,
167
163
pastV : past ,
168
164
pastChanged : changed ,
169
165
})
170
- ts .changedKeys [k ] = & tempStorage {nil , true }
166
+ ts .changedKeys [string ( key ) ] = & tempStorage {nil , true }
171
167
return nil
172
168
}
173
169
@@ -188,13 +184,13 @@ func (ts *TState) Rollback(_ context.Context, restorePoint int) {
188
184
//
189
185
// remove: Removed key that was modified for first time in run
190
186
if ! op .pastChanged {
191
- delete (ts .changedKeys , op .k )
187
+ delete (ts .changedKeys , string ( op .k ) )
192
188
continue
193
189
}
194
190
// insert: Modified key for the nth time
195
191
//
196
192
// remove: Removed key that was previously modified in run
197
- ts .changedKeys [op .k ] = & tempStorage {op .pastV , ! op .pastExists }
193
+ ts .changedKeys [string ( op .k ) ] = & tempStorage {op .pastV , ! op .pastExists }
198
194
}
199
195
ts .ops = ts .ops [:restorePoint ]
200
196
}
0 commit comments