20
20
#include " Firestore/core/src/firebase/firestore/util/hard_assert.h"
21
21
#include " Firestore/core/src/firebase/firestore/util/log.h"
22
22
#include " absl/memory/memory.h"
23
+ #include " absl/strings/str_cat.h"
23
24
#include " leveldb/write_batch.h"
24
25
25
26
using leveldb::DB;
@@ -161,8 +162,7 @@ const WriteOptions& LevelDbTransaction::DefaultWriteOptions() {
161
162
return options;
162
163
}
163
164
164
- void LevelDbTransaction::Put (const absl::string_view& key,
165
- const absl::string_view& value) {
165
+ void LevelDbTransaction::Put (absl::string_view key, absl::string_view value) {
166
166
std::string key_string (key);
167
167
std::string value_string (value);
168
168
mutations_[key_string] = value_string;
@@ -175,13 +175,12 @@ LevelDbTransaction::NewIterator() {
175
175
return absl::make_unique<LevelDbTransaction::Iterator>(this );
176
176
}
177
177
178
- Status LevelDbTransaction::Get (const absl::string_view& key,
179
- std::string* value) {
178
+ Status LevelDbTransaction::Get (absl::string_view key, std::string* value) {
180
179
std::string key_string (key);
181
180
if (deletions_.find (key_string) != deletions_.end ()) {
182
181
return Status::NotFound (key_string + " is not present in the transaction" );
183
182
} else {
184
- Mutations::iterator iter ( mutations_.find (key_string)) ;
183
+ Mutations::iterator iter{ mutations_.find (key_string)} ;
185
184
if (iter != mutations_.end ()) {
186
185
*value = iter->second ;
187
186
return Status::OK ();
@@ -191,7 +190,7 @@ Status LevelDbTransaction::Get(const absl::string_view& key,
191
190
}
192
191
}
193
192
194
- void LevelDbTransaction::Delete (const absl::string_view& key) {
193
+ void LevelDbTransaction::Delete (absl::string_view key) {
195
194
std::string to_delete (key);
196
195
deletions_.insert (to_delete);
197
196
mutations_.erase (to_delete);
@@ -200,12 +199,12 @@ void LevelDbTransaction::Delete(const absl::string_view& key) {
200
199
201
200
void LevelDbTransaction::Commit () {
202
201
WriteBatch batch;
203
- for (auto it = deletions_. begin (); it != deletions_. end (); it++ ) {
204
- batch.Delete (*it );
202
+ for (const auto & deletion : deletions_) {
203
+ batch.Delete (deletion );
205
204
}
206
205
207
- for (auto it = mutations_. begin (); it != mutations_. end (); it++ ) {
208
- batch.Put (it-> first , it-> second );
206
+ for (const auto & entry : mutations_) {
207
+ batch.Put (entry. first , entry. second );
209
208
}
210
209
211
210
LOG_DEBUG (" Committing transaction: %s" , ToString ());
@@ -216,21 +215,21 @@ void LevelDbTransaction::Commit() {
216
215
}
217
216
218
217
std::string LevelDbTransaction::ToString () {
219
- std::string dest (" <LevelDbTransaction " + label_ + " : " );
220
- int64_t changes = deletions_.size () + mutations_.size ();
221
- int64_t bytes = 0 ; // accumulator for size of individual mutations.
218
+ std::string dest = absl::StrCat (" <LevelDbTransaction " , label_, " : " );
219
+ size_t changes = deletions_.size () + mutations_.size ();
220
+ size_t bytes = 0 ; // accumulator for size of individual mutations.
222
221
dest += std::to_string (changes) + " changes " ;
223
222
std::string items; // accumulator for individual changes.
224
- for (auto it = deletions_. begin (); it != deletions_. end (); it++ ) {
225
- items += " \n - Delete " + DescribeKey (*it );
223
+ for (const auto & deletion : deletions_) {
224
+ absl::StrAppend (& items, " \n - Delete " , DescribeKey (deletion) );
226
225
}
227
- for (auto it = mutations_. begin (); it != mutations_. end (); it++ ) {
228
- int64_t change_bytes = it-> second .length ();
226
+ for (const auto & entry : mutations_) {
227
+ size_t change_bytes = entry. second .size ();
229
228
bytes += change_bytes;
230
- items += " \n - Put " + DescribeKey (it-> first ) + " (" +
231
- std::to_string (change_bytes) + " bytes)" ;
229
+ absl::StrAppend (& items, " \n - Put " , DescribeKey (entry. first ), " (" ,
230
+ change_bytes, " bytes)" ) ;
232
231
}
233
- dest += " (" + std::to_string ( bytes) + " bytes):" + items + " >" ;
232
+ absl::StrAppend (& dest, " (" , bytes, " bytes):" , items, " >" ) ;
234
233
return dest;
235
234
}
236
235
0 commit comments