Commit b13195f2 by Rose

Use const and static for member functions

This shows that these are member functions that do not modify a class's data.
parent eba70b1c
...@@ -261,7 +261,7 @@ void CRC32::Extend(uint32_t* crc, const void* bytes, size_t length) const { ...@@ -261,7 +261,7 @@ void CRC32::Extend(uint32_t* crc, const void* bytes, size_t length) const {
const uint8_t* e = p + length; const uint8_t* e = p + length;
uint32_t l = *crc; uint32_t l = *crc;
auto step_one_byte = [this, &p, &l] () { auto step_one_byte = [this, &p, &l]() {
int c = (l & 0xff) ^ *p++; int c = (l & 0xff) ^ *p++;
l = this->table0_[c] ^ (l >> 8); l = this->table0_[c] ^ (l >> 8);
}; };
...@@ -359,7 +359,7 @@ void CRC32::Extend(uint32_t* crc, const void* bytes, size_t length) const { ...@@ -359,7 +359,7 @@ void CRC32::Extend(uint32_t* crc, const void* bytes, size_t length) const {
void CRC32::ExtendByZeroesImpl(uint32_t* crc, size_t length, void CRC32::ExtendByZeroesImpl(uint32_t* crc, size_t length,
const uint32_t zeroes_table[256], const uint32_t zeroes_table[256],
const uint32_t poly_table[256]) const { const uint32_t poly_table[256]) {
if (length != 0) { if (length != 0) {
uint32_t l = *crc; uint32_t l = *crc;
// For each ZEROES_BASE_LG bits in length // For each ZEROES_BASE_LG bits in length
......
...@@ -118,9 +118,9 @@ class CRC32 : public CRCImpl { ...@@ -118,9 +118,9 @@ class CRC32 : public CRCImpl {
// //
// These will be set to reverse_zeroes_ and reverse_table0_ for Unextend, and // These will be set to reverse_zeroes_ and reverse_table0_ for Unextend, and
// CRC32::zeroes_ and CRC32::table0_ for Extend. // CRC32::zeroes_ and CRC32::table0_ for Extend.
void ExtendByZeroesImpl(uint32_t* crc, size_t length, static void ExtendByZeroesImpl(uint32_t* crc, size_t length,
const uint32_t zeroes_table[256], const uint32_t zeroes_table[256],
const uint32_t poly_table[256]) const; const uint32_t poly_table[256]);
uint32_t table0_[256]; // table of byte extensions uint32_t table0_[256]; // table of byte extensions
uint32_t zeroes_[256]; // table of zero extensions uint32_t zeroes_[256]; // table of zero extensions
......
...@@ -160,7 +160,6 @@ class CordBuffer { ...@@ -160,7 +160,6 @@ class CordBuffer {
// for more information on buffer capacities and intended usage. // for more information on buffer capacities and intended usage.
static CordBuffer CreateWithDefaultLimit(size_t capacity); static CordBuffer CreateWithDefaultLimit(size_t capacity);
// CordBuffer::CreateWithCustomLimit() // CordBuffer::CreateWithCustomLimit()
// //
// Creates a CordBuffer instance of the desired `capacity` rounded to an // Creates a CordBuffer instance of the desired `capacity` rounded to an
...@@ -336,7 +335,7 @@ class CordBuffer { ...@@ -336,7 +335,7 @@ class CordBuffer {
} }
// Returns the available area of the internal SSO data // Returns the available area of the internal SSO data
absl::Span<char> long_available() { absl::Span<char> long_available() const {
assert(!is_short()); assert(!is_short());
const size_t length = long_rep.rep->length; const size_t length = long_rep.rep->length;
return absl::Span<char>(long_rep.rep->Data() + length, return absl::Span<char>(long_rep.rep->Data() + length,
......
...@@ -1015,7 +1015,7 @@ struct Buffer { ...@@ -1015,7 +1015,7 @@ struct Buffer {
--end; --end;
} }
char &back() { char &back() const {
assert(begin < end); assert(begin < end);
return end[-1]; return end[-1];
} }
......
...@@ -60,19 +60,23 @@ absl::string_view GenericFind(absl::string_view text, ...@@ -60,19 +60,23 @@ absl::string_view GenericFind(absl::string_view text,
// Finds using absl::string_view::find(), therefore the length of the found // Finds using absl::string_view::find(), therefore the length of the found
// delimiter is delimiter.length(). // delimiter is delimiter.length().
struct LiteralPolicy { struct LiteralPolicy {
size_t Find(absl::string_view text, absl::string_view delimiter, size_t pos) { static size_t Find(absl::string_view text, absl::string_view delimiter,
size_t pos) {
return text.find(delimiter, pos); return text.find(delimiter, pos);
} }
size_t Length(absl::string_view delimiter) { return delimiter.length(); } static size_t Length(absl::string_view delimiter) {
return delimiter.length();
}
}; };
// Finds using absl::string_view::find_first_of(), therefore the length of the // Finds using absl::string_view::find_first_of(), therefore the length of the
// found delimiter is 1. // found delimiter is 1.
struct AnyOfPolicy { struct AnyOfPolicy {
size_t Find(absl::string_view text, absl::string_view delimiter, size_t pos) { static size_t Find(absl::string_view text, absl::string_view delimiter,
size_t pos) {
return text.find_first_of(delimiter, pos); return text.find_first_of(delimiter, pos);
} }
size_t Length(absl::string_view /* delimiter */) { return 1; } static size_t Length(absl::string_view /* delimiter */) { return 1; }
}; };
} // namespace } // namespace
...@@ -123,8 +127,7 @@ ByLength::ByLength(ptrdiff_t length) : length_(length) { ...@@ -123,8 +127,7 @@ ByLength::ByLength(ptrdiff_t length) : length_(length) {
ABSL_RAW_CHECK(length > 0, ""); ABSL_RAW_CHECK(length > 0, "");
} }
absl::string_view ByLength::Find(absl::string_view text, absl::string_view ByLength::Find(absl::string_view text, size_t pos) const {
size_t pos) const {
pos = std::min(pos, text.size()); // truncate `pos` pos = std::min(pos, text.size()); // truncate `pos`
absl::string_view substr = text.substr(pos); absl::string_view substr = text.substr(pos);
// If the string is shorter than the chunk size we say we // If the string is shorter than the chunk size we say we
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment