Skip to content

Commit 7a0a416

Browse files
committed
feat(storage): use crc32c dep from abseil
1 parent 8170800 commit 7a0a416

File tree

3 files changed

+13
-42
lines changed

3 files changed

+13
-42
lines changed

google/cloud/storage/internal/crc32c.cc

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,16 @@
1414

1515
#include "google/cloud/storage/internal/crc32c.h"
1616
#include "absl/base/config.h"
17-
#if defined(ABSL_LTS_RELEASE_VERSION) && ABSL_LTS_RELEASE_VERSION >= 20230125
1817
#include "absl/crc/crc32c.h"
19-
#define GOOGLE_CLOUD_CPP_USE_ABSL_CRC32C 1
20-
#else
21-
#define GOOGLE_CLOUD_CPP_USE_ABSL_CRC32C 0
22-
#endif // ABSL_LTS_RELEASE_VERSION
23-
#include <crc32c/crc32c.h>
2418

2519
namespace google {
2620
namespace cloud {
2721
namespace storage_internal {
2822
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
2923

3024
std::uint32_t ExtendCrc32c(std::uint32_t crc, absl::string_view data) {
31-
return crc32c::Extend(crc, reinterpret_cast<uint8_t const*>(data.data()),
32-
data.size());
25+
return static_cast<std::uint32_t>(
26+
absl::ExtendCrc32c(absl::crc32c_t{crc}, data));
3327
}
3428

3529
std::uint32_t ExtendCrc32c(std::uint32_t crc,
@@ -47,8 +41,6 @@ std::uint32_t ExtendCrc32c(std::uint32_t crc, absl::Cord const& data) {
4741
return crc;
4842
}
4943

50-
#if GOOGLE_CLOUD_CPP_USE_ABSL_CRC32C
51-
5244
std::uint32_t ExtendCrc32c(std::uint32_t crc, absl::string_view data,
5345
std::uint32_t data_crc) {
5446
return static_cast<std::uint32_t>(absl::ConcatCrc32c(
@@ -69,27 +61,7 @@ std::uint32_t ExtendCrc32c(std::uint32_t crc, absl::Cord const& data,
6961
absl::crc32c_t{crc}, absl::crc32c_t{data_crc}, data.size()));
7062
}
7163

72-
#else
73-
74-
std::uint32_t ExtendCrc32c(std::uint32_t crc, absl::string_view data,
75-
std::uint32_t /*data_crc*/) {
76-
return ExtendCrc32c(crc, data);
77-
}
78-
79-
std::uint32_t ExtendCrc32c(std::uint32_t crc,
80-
storage::internal::ConstBufferSequence const& data,
81-
std::uint32_t /*data_crc*/) {
82-
return ExtendCrc32c(crc, data);
83-
}
84-
85-
std::uint32_t ExtendCrc32c(std::uint32_t crc, absl::Cord const& data,
86-
std::uint32_t /*data_crc*/) {
87-
return ExtendCrc32c(crc, data);
88-
}
89-
90-
#endif // GOOGLE_CLOUD_CPP_USE_ABSL_CRC32C
91-
9264
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
9365
} // namespace storage_internal
9466
} // namespace cloud
95-
} // namespace google
67+
} // namespace google

google/cloud/storage/internal/crc32c.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
#include "google/cloud/storage/internal/const_buffer.h"
1919
#include "google/cloud/storage/version.h"
20+
#include "absl/crc/crc32c.h"
2021
#include "absl/strings/cord.h"
2122
#include "absl/strings/string_view.h"
2223
#include <cstdint>
@@ -57,4 +58,4 @@ GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
5758
} // namespace cloud
5859
} // namespace google
5960

60-
#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_STORAGE_INTERNAL_CRC32C_H
61+
#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_STORAGE_INTERNAL_CRC32C_H

google/cloud/storage/internal/crc32c_benchmark.cc

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
// limitations under the License.
1414

1515
#include "google/cloud/storage/internal/crc32c.h"
16+
#include "absl/crc/crc32c.h"
1617
#include <benchmark/benchmark.h>
17-
#include <crc32c/crc32c.h>
1818
#include <string>
1919

2020
namespace google {
@@ -33,31 +33,29 @@ namespace {
3333
// ----------------------------------------------------------------------
3434
// Benchmark Time CPU Iterations
3535
// ----------------------------------------------------------------------
36-
// BM_Crc32cDuplicateNonAbseil 25520759 ns 25520833 ns 28
36+
// BM_Crc32cExtendStringView 25520759 ns 25520833 ns 28
3737
// BM_Crc32cDuplicate 24168074 ns 24168122 ns 28
3838
// BM_Crc32cConcat 12213494 ns 12213077 ns 57
3939

4040
auto constexpr kMessage = 2 * 1024 * std::size_t{1024};
4141
auto constexpr kWriteSize = 16 * kMessage;
4242
auto constexpr kUploadSize = 8 * kWriteSize;
4343

44-
void BM_Crc32cDuplicateNonAbseil(benchmark::State& state) {
44+
void BM_Crc32cExtendStringView(benchmark::State& state) {
4545
auto buffer = std::string(kWriteSize, '0');
46-
auto crc = std::uint32_t{0};
46+
auto crc = absl::crc32c_t{0};
4747
for (auto _ : state) {
4848
for (std::size_t offset = 0; offset < kUploadSize; offset += kWriteSize) {
4949
for (std::size_t m = 0; m < kWriteSize; m += kMessage) {
5050
auto w = absl::string_view{buffer}.substr(m, kMessage);
51-
benchmark::DoNotOptimize(crc32c::Crc32c(w.data(), w.size()));
51+
benchmark::DoNotOptimize(absl::ComputeCrc32c(w));
5252
}
53-
crc = crc32c::Extend(crc,
54-
reinterpret_cast<std::uint8_t const*>(buffer.data()),
55-
buffer.size());
53+
crc = absl::ExtendCrc32c(crc, buffer);
5654
}
5755
}
5856
benchmark::DoNotOptimize(crc);
5957
}
60-
BENCHMARK(BM_Crc32cDuplicateNonAbseil);
58+
BENCHMARK(BM_Crc32cExtendStringView);
6159

6260
void BM_Crc32cDuplicate(benchmark::State& state) {
6361
auto buffer = std::string(kWriteSize, '0');
@@ -95,4 +93,4 @@ BENCHMARK(BM_Crc32cConcat);
9593
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
9694
} // namespace storage_internal
9795
} // namespace cloud
98-
} // namespace google
96+
} // namespace google

0 commit comments

Comments
 (0)