aboutsummaryrefslogtreecommitdiff
path: root/absl/crc/crc32c.cc
diff options
context:
space:
mode:
authorDerek Mauro <dmauro@google.com>2022-11-29 09:19:04 -0800
committerCopybara-Service <copybara-worker@google.com>2022-11-29 09:19:57 -0800
commitd03cced7d552ece168c6db92acb3a7c379aae0c0 (patch)
treef5975b279620e410ad017ee09bceaee4c676fec1 /absl/crc/crc32c.cc
parent82196f059f213c50738142a799bb166b2971950d (diff)
downloadabseil-d03cced7d552ece168c6db92acb3a7c379aae0c0.tar.gz
abseil-d03cced7d552ece168c6db92acb3a7c379aae0c0.tar.bz2
abseil-d03cced7d552ece168c6db92acb3a7c379aae0c0.zip
CRC: Make crc32c_t as a class for explicit control of operators
The motivation is to explicitly remove and document dangerous operations like adding crc32c_t to a set, because equality is not enough to guarantee uniqueness. PiperOrigin-RevId: 491656425 Change-Id: I7b4dadc1a59ea9861e6ec7a929d64b5746467832
Diffstat (limited to 'absl/crc/crc32c.cc')
-rw-r--r--absl/crc/crc32c.cc11
1 files changed, 6 insertions, 5 deletions
diff --git a/absl/crc/crc32c.cc b/absl/crc/crc32c.cc
index 82865df5..169826f5 100644
--- a/absl/crc/crc32c.cc
+++ b/absl/crc/crc32c.cc
@@ -55,7 +55,7 @@ crc32c_t ExtendCrc32cInternal(crc32c_t initial_crc,
} // namespace crc_internal
crc32c_t ComputeCrc32c(absl::string_view buf) {
- return ExtendCrc32c(ToCrc32c(0), buf);
+ return ExtendCrc32c(crc32c_t{0}, buf);
}
crc32c_t ExtendCrc32cByZeroes(crc32c_t initial_crc, size_t length) {
@@ -67,7 +67,7 @@ crc32c_t ExtendCrc32cByZeroes(crc32c_t initial_crc, size_t length) {
crc32c_t ConcatCrc32c(crc32c_t lhs_crc, crc32c_t rhs_crc, size_t rhs_len) {
uint32_t result = static_cast<uint32_t>(lhs_crc);
CrcEngine()->ExtendByZeroes(&result, rhs_len);
- return static_cast<crc32c_t>(result) ^ rhs_crc;
+ return crc32c_t{result ^ static_cast<uint32_t>(rhs_crc)};
}
crc32c_t RemoveCrc32cPrefix(crc32c_t crc_a, crc32c_t crc_ab, size_t length_b) {
@@ -89,9 +89,10 @@ crc32c_t MemcpyCrc32c(void* dest, const void* src, size_t count,
// This operation has a runtime cost of O(log(`suffix_len`))
crc32c_t RemoveCrc32cSuffix(crc32c_t full_string_crc, crc32c_t suffix_crc,
size_t suffix_len) {
- crc32c_t crc_with_suffix_zeroed =
- suffix_crc ^ full_string_crc ^
- ExtendCrc32cByZeroes(ToCrc32c(0), suffix_len);
+ crc32c_t crc_with_suffix_zeroed = crc32c_t{
+ static_cast<uint32_t>(suffix_crc) ^
+ static_cast<uint32_t>(full_string_crc) ^
+ static_cast<uint32_t>(ExtendCrc32cByZeroes(crc32c_t{0}, suffix_len))};
return crc_internal::UnextendCrc32cByZeroes(
crc_with_suffix_zeroed, suffix_len);
}