Skip to content

Commit 79e3883

Browse files
committed
Fix style guide violations and extract GetChecksumAlgorithm
1 parent 67042df commit 79e3883

6 files changed

Lines changed: 15 additions & 21 deletions

File tree

google/cloud/storage/benchmarks/throughput_experiment.cc

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,13 @@ std::string ExtractUploadId(std::string v) {
6363
return v.substr(pos + std::strlen(kRestField));
6464
}
6565

66+
gcs::ChecksumAlgorithm GetChecksumAlgorithm(bool enable_crc32c,
67+
bool enable_md5) {
68+
if (enable_crc32c) return gcs::ChecksumAlgorithm::kCrc32c;
69+
if (enable_md5) return gcs::ChecksumAlgorithm::kMD5;
70+
return gcs::ChecksumAlgorithm::kNone;
71+
}
72+
6673
class ResumableUpload : public ThroughputExperiment {
6774
public:
6875
explicit ResumableUpload(google::cloud::storage::Client client,
@@ -80,14 +87,10 @@ class ResumableUpload : public ThroughputExperiment {
8087

8188
auto const start = std::chrono::system_clock::now();
8289
auto timer = Timer::PerThread();
83-
auto writer =
84-
client_.WriteObject(
90+
auto writer = client_.WriteObject(
8591
bucket_name, object_name,
8692
google::cloud::Options{}.set<gcs::UploadChecksumValidationOption>(
87-
config.enable_crc32c
88-
? gcs::ChecksumAlgorithm::kCrc32c
89-
: (config.enable_md5 ? gcs::ChecksumAlgorithm::kMD5
90-
: gcs::ChecksumAlgorithm::kNone)));
93+
GetChecksumAlgorithm(config.enable_crc32c, config.enable_md5)));
9194
auto upload_id = ExtractUploadId(writer.resumable_session_id());
9295
for (std::int64_t offset = 0; offset < config.object_size;
9396
offset += config.app_buffer_size) {
@@ -159,10 +162,7 @@ class SimpleUpload : public ThroughputExperiment {
159162
client_.InsertObject(
160163
bucket_name, object_name, data,
161164
google::cloud::Options{}.set<gcs::UploadChecksumValidationOption>(
162-
config.enable_crc32c
163-
? gcs::ChecksumAlgorithm::kCrc32c
164-
: (config.enable_md5 ? gcs::ChecksumAlgorithm::kMD5
165-
: gcs::ChecksumAlgorithm::kNone)));
165+
GetChecksumAlgorithm(config.enable_crc32c, config.enable_md5)));
166166
auto const usage = timer.Sample();
167167
auto generation = object_metadata
168168
? std::to_string(object_metadata->generation())
@@ -221,10 +221,7 @@ class DownloadObject : public ThroughputExperiment {
221221
client_.ReadObject(
222222
bucket_name, object_name, read_range,
223223
google::cloud::Options{}.set<gcs::DownloadChecksumValidationOption>(
224-
config.enable_crc32c
225-
? gcs::ChecksumAlgorithm::kCrc32c
226-
: (config.enable_md5 ? gcs::ChecksumAlgorithm::kMD5
227-
: gcs::ChecksumAlgorithm::kNone)));
224+
GetChecksumAlgorithm(config.enable_crc32c, config.enable_md5)));
228225
std::int64_t transfer_size = 0;
229226
while (!reader.eof() && !reader.bad()) {
230227
reader.read(buffer.data(), buffer.size());

google/cloud/storage/client_object_test.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,6 @@ TEST_F(ObjectTest, ReadObject) {
234234
EXPECT_EQ(actual.gcount(), 1024);
235235
}
236236

237-
238237
TEST_F(ObjectTest, WriteObject) {
239238
EXPECT_CALL(*mock_, CreateResumableUpload)
240239
.WillOnce(Return(TransientError()))

google/cloud/storage/internal/checksum_helpers.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ inline HashDisabled GetDownloadChecksumSettings(Options const& options) {
4040
disable_crc32c = (algo != ChecksumAlgorithm::kCrc32c);
4141
}
4242

43-
4443
return {disable_md5, disable_crc32c};
4544
}
4645

@@ -53,7 +52,6 @@ inline HashDisabled GetUploadChecksumSettings(Options const& options) {
5352
disable_crc32c = (algo != ChecksumAlgorithm::kCrc32c);
5453
}
5554

56-
5755
return {disable_md5, disable_crc32c};
5856
}
5957

google/cloud/storage/internal/hash_function.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ std::unique_ptr<HashFunction> CreateHashFunction(
6464
ReadObjectRangeRequest const& request) {
6565
if (request.RequiresRangeHeader()) return CreateNullHashFunction();
6666

67-
auto const settings = GetDownloadChecksumSettings(google::cloud::internal::CurrentOptions());
67+
auto const settings = GetDownloadChecksumSettings(
68+
google::cloud::internal::CurrentOptions());
6869
auto const disable_md5 = settings.md5;
6970
auto const disable_crc32c = settings.crc32c;
7071
if (disable_md5 && disable_crc32c) {
@@ -84,7 +85,8 @@ std::unique_ptr<HashFunction> CreateHashFunction(
8485
return CreateNullHashFunction();
8586
}
8687

87-
auto const settings = GetUploadChecksumSettings(google::cloud::internal::CurrentOptions());
88+
auto const settings = GetUploadChecksumSettings(
89+
google::cloud::internal::CurrentOptions());
8890
return CreateHashFunction(request.GetOption<Crc32cChecksumValue>(),
8991
settings.crc32c, request.GetOption<MD5HashValue>(),
9092
settings.md5);

google/cloud/storage/internal/object_requests_test.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1117,7 +1117,6 @@ TEST(DefaultCtorsWork, Trivial) {
11171117
EXPECT_FALSE(ReadFromOffset().has_value());
11181118
EXPECT_FALSE(ReadLast().has_value());
11191119
EXPECT_FALSE(MD5HashValue().has_value());
1120-
11211120
EXPECT_FALSE(Crc32cChecksumValue().has_value());
11221121
EXPECT_FALSE(WithObjectMetadata().has_value());
11231122
EXPECT_FALSE(UseResumableUploadSession().has_value());

google/cloud/storage/internal/object_write_streambuf_test.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -688,7 +688,6 @@ TEST(ObjectWriteStreambufTest, FlushFinalWithHashes) {
688688
});
689689

690690
ResumableUploadRequest request;
691-
692691
ObjectWriteStreambuf streambuf(
693692
std::move(mock), request, "test-only-upload-id",
694693
/*committed_size=*/0, std::nullopt, /*max_buffer_size=*/quantum,

0 commit comments

Comments
 (0)