From 808d0e33537a9f9c2477f014e23f95acf2c24613 Mon Sep 17 00:00:00 2001 From: Adam Simpkins Date: Tue, 29 Jun 2021 11:49:00 -0700 Subject: [PATCH] [caffe2] update make_mnist_db and make_image_db to move strings into DB::Put() (#60919) Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/60919 Update make_mnist_db.cc and make_image_db.cc to work with the DB API changes in D29204425 (https://github.com/pytorch/pytorch/commit/00896cb9ed931bb816cf1a5e5f13ddc6b229378b). This is similar to the changes to make_cifar_db.cc landed in D29374754 (https://github.com/pytorch/pytorch/commit/394f60b0fcd834bd2613a482b28408f275c0022b). ghstack-source-id: 132621346 Test Plan: buck build caffe2/binaries/... Reviewed By: valmikir Differential Revision: D29447314 fbshipit-source-id: 33aff85c24d8b785211287de23d46704c7eb0726 --- binaries/make_image_db.cc | 3 +-- binaries/make_mnist_db.cc | 4 +--- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/binaries/make_image_db.cc b/binaries/make_image_db.cc index fbbf4d9d486e..b2f8135f5da2 100644 --- a/binaries/make_image_db.cc +++ b/binaries/make_image_db.cc @@ -243,7 +243,6 @@ void ConvertImageDataset( constexpr auto key_max_length = 256; char key_cstr[key_max_length]; - string value; int count = 0; for (auto i = 0; i < lines.size(); i++) { // Get serialized proto for this entry @@ -255,7 +254,7 @@ void ConvertImageDataset( DCHECK_LE(key_len, sizeof(key_cstr)); // Put in db - transaction->Put(string(key_cstr), value); + transaction->Put(string(key_cstr), std::move(value)); if (++count % 1000 == 0) { // Commit the current writes. diff --git a/binaries/make_mnist_db.cc b/binaries/make_mnist_db.cc index 005c9ac7d811..53e9d87d0e15 100644 --- a/binaries/make_mnist_db.cc +++ b/binaries/make_mnist_db.cc @@ -91,7 +91,6 @@ void convert_dataset(const char* image_filename, const char* label_filename, int count = 0; const int kMaxKeyLength = 11; char key_cstr[kMaxKeyLength]; - string value; TensorProtos protos; TensorProto* data = protos.add_protos(); @@ -119,11 +118,10 @@ void convert_dataset(const char* image_filename, const char* label_filename, } label->set_int32_data(0, static_cast(label_value)); snprintf(key_cstr, kMaxKeyLength, "%08d", item_id); - protos.SerializeToString(&value); string keystr(key_cstr); // Put in db - transaction->Put(keystr, value); + transaction->Put(keystr, protos.SerializeAsString()); if (++count % 1000 == 0) { transaction->Commit(); }