[c++14] Simplify macro thats always the same now (#29601)

* [c++14] Simplify macro thats always the same now

* move bitset too
pull/29784/head
Craig Tiller 3 years ago committed by GitHub
parent 5a204075da
commit 7faa624d8e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 16
      src/core/lib/gprpp/bitset.h
  2. 16
      src/core/lib/slice/percent_encoding.cc

@ -24,12 +24,6 @@
#include "src/core/lib/gpr/useful.h" #include "src/core/lib/gpr/useful.h"
#if __cplusplus > 201103l
#define GRPC_BITSET_CONSTEXPR_MUTATOR constexpr
#else
#define GRPC_BITSET_CONSTEXPR_MUTATOR
#endif
namespace grpc_core { namespace grpc_core {
// Given a bit count as an integer, vend as member type `Type` a type with // Given a bit count as an integer, vend as member type `Type` a type with
@ -90,12 +84,10 @@ class BitSet {
constexpr BitSet() : units_{} {} constexpr BitSet() : units_{} {}
// Set bit i to true // Set bit i to true
GRPC_BITSET_CONSTEXPR_MUTATOR void set(int i) { constexpr void set(int i) { units_[unit_for(i)] |= mask_for(i); }
units_[unit_for(i)] |= mask_for(i);
}
// Set bit i to is_set // Set bit i to is_set
GRPC_BITSET_CONSTEXPR_MUTATOR void set(int i, bool is_set) { constexpr void set(int i, bool is_set) {
if (is_set) { if (is_set) {
set(i); set(i);
} else { } else {
@ -104,9 +96,7 @@ class BitSet {
} }
// Set bit i to false // Set bit i to false
GRPC_BITSET_CONSTEXPR_MUTATOR void clear(int i) { constexpr void clear(int i) { units_[unit_for(i)] &= ~mask_for(i); }
units_[unit_for(i)] &= ~mask_for(i);
}
// Return true if bit i is set // Return true if bit i is set
constexpr bool is_set(int i) const { constexpr bool is_set(int i) const {

@ -30,20 +30,12 @@
#include "src/core/lib/gprpp/bitset.h" #include "src/core/lib/gprpp/bitset.h"
#if __cplusplus > 201103l
#define GRPC_PCTENCODE_CONSTEXPR_FN constexpr
#define GRPC_PCTENCODE_CONSTEXPR_VALUE constexpr
#else
#define GRPC_PCTENCODE_CONSTEXPR_FN
#define GRPC_PCTENCODE_CONSTEXPR_VALUE const
#endif
namespace grpc_core { namespace grpc_core {
namespace { namespace {
class UrlTable : public BitSet<256> { class UrlTable : public BitSet<256> {
public: public:
GRPC_PCTENCODE_CONSTEXPR_FN UrlTable() { constexpr UrlTable() {
for (int i = 'a'; i <= 'z'; i++) set(i); for (int i = 'a'; i <= 'z'; i++) set(i);
for (int i = 'A'; i <= 'Z'; i++) set(i); for (int i = 'A'; i <= 'Z'; i++) set(i);
for (int i = '0'; i <= '9'; i++) set(i); for (int i = '0'; i <= '9'; i++) set(i);
@ -54,11 +46,11 @@ class UrlTable : public BitSet<256> {
} }
}; };
GRPC_PCTENCODE_CONSTEXPR_VALUE UrlTable g_url_table; constexpr UrlTable g_url_table;
class CompatibleTable : public BitSet<256> { class CompatibleTable : public BitSet<256> {
public: public:
GRPC_PCTENCODE_CONSTEXPR_FN CompatibleTable() { constexpr CompatibleTable() {
for (int i = 32; i <= 126; i++) { for (int i = 32; i <= 126; i++) {
if (i == '%') continue; if (i == '%') continue;
set(i); set(i);
@ -66,7 +58,7 @@ class CompatibleTable : public BitSet<256> {
} }
}; };
GRPC_PCTENCODE_CONSTEXPR_VALUE CompatibleTable g_compatible_table; constexpr CompatibleTable g_compatible_table;
// Map PercentEncodingType to a lookup table of legal symbols for that encoding. // Map PercentEncodingType to a lookup table of legal symbols for that encoding.
const BitSet<256>& LookupTableForPercentEncodingType(PercentEncodingType type) { const BitSet<256>& LookupTableForPercentEncodingType(PercentEncodingType type) {

Loading…
Cancel
Save