diff options
Diffstat (limited to 'src/core/lib/slice')
-rw-r--r-- | src/core/lib/slice/b64.cc | 30 | ||||
-rw-r--r-- | src/core/lib/slice/percent_encoding.cc | 10 | ||||
-rw-r--r-- | src/core/lib/slice/slice.cc | 64 | ||||
-rw-r--r-- | src/core/lib/slice/slice_buffer.cc | 22 | ||||
-rw-r--r-- | src/core/lib/slice/slice_hash_table.cc | 4 | ||||
-rw-r--r-- | src/core/lib/slice/slice_intern.cc | 30 | ||||
-rw-r--r-- | src/core/lib/slice/slice_string_helpers.cc | 4 |
7 files changed, 82 insertions, 82 deletions
diff --git a/src/core/lib/slice/b64.cc b/src/core/lib/slice/b64.cc index 5c6610c372..1d938be11c 100644 --- a/src/core/lib/slice/b64.cc +++ b/src/core/lib/slice/b64.cc @@ -58,7 +58,7 @@ char* grpc_base64_encode(const void* vdata, size_t data_size, int url_safe, int multiline) { size_t result_projected_size = grpc_base64_estimate_encoded_size(data_size, url_safe, multiline); - char* result = (char*)gpr_malloc(result_projected_size); + char* result = static_cast<char*>(gpr_malloc(result_projected_size)); grpc_base64_encode_core(result, vdata, data_size, url_safe, multiline); return result; } @@ -75,7 +75,7 @@ size_t grpc_base64_estimate_encoded_size(size_t data_size, int url_safe, void grpc_base64_encode_core(char* result, const void* vdata, size_t data_size, int url_safe, int multiline) { - const unsigned char* data = (const unsigned char*)vdata; + const unsigned char* data = static_cast<const unsigned char*>(vdata); const char* base64_chars = url_safe ? base64_url_safe_chars : base64_url_unsafe_chars; const size_t result_projected_size = @@ -128,16 +128,16 @@ grpc_slice grpc_base64_decode(const char* b64, int url_safe) { static void decode_one_char(const unsigned char* codes, unsigned char* result, size_t* result_offset) { - uint32_t packed = ((uint32_t)codes[0] << 2) | ((uint32_t)codes[1] >> 4); - result[(*result_offset)++] = (unsigned char)packed; + uint32_t packed = (static_cast<uint32_t>(codes[0]) << 2) | (static_cast<uint32_t>(codes[1]) >> 4); + result[(*result_offset)++] = static_cast<unsigned char>(packed); } static void decode_two_chars(const unsigned char* codes, unsigned char* result, size_t* result_offset) { - uint32_t packed = ((uint32_t)codes[0] << 10) | ((uint32_t)codes[1] << 4) | - ((uint32_t)codes[2] >> 2); - result[(*result_offset)++] = (unsigned char)(packed >> 8); - result[(*result_offset)++] = (unsigned char)(packed); + uint32_t packed = (static_cast<uint32_t>(codes[0]) << 10) | (static_cast<uint32_t>(codes[1]) << 4) | + (static_cast<uint32_t>(codes[2]) >> 2); + result[(*result_offset)++] = static_cast<unsigned char>(packed >> 8); + result[(*result_offset)++] = static_cast<unsigned char>(packed); } static int decode_group(const unsigned char* codes, size_t num_codes, @@ -175,11 +175,11 @@ static int decode_group(const unsigned char* codes, size_t num_codes, decode_two_chars(codes, result, result_offset); } else { /* No padding. */ - uint32_t packed = ((uint32_t)codes[0] << 18) | ((uint32_t)codes[1] << 12) | - ((uint32_t)codes[2] << 6) | codes[3]; - result[(*result_offset)++] = (unsigned char)(packed >> 16); - result[(*result_offset)++] = (unsigned char)(packed >> 8); - result[(*result_offset)++] = (unsigned char)(packed); + uint32_t packed = (static_cast<uint32_t>(codes[0]) << 18) | (static_cast<uint32_t>(codes[1]) << 12) | + (static_cast<uint32_t>(codes[2]) << 6) | codes[3]; + result[(*result_offset)++] = static_cast<unsigned char>(packed >> 16); + result[(*result_offset)++] = static_cast<unsigned char>(packed >> 8); + result[(*result_offset)++] = static_cast<unsigned char>(packed); } return 1; } @@ -193,7 +193,7 @@ grpc_slice grpc_base64_decode_with_len(const char* b64, size_t b64_len, size_t num_codes = 0; while (b64_len--) { - unsigned char c = (unsigned char)(*b64++); + unsigned char c = static_cast<unsigned char>(*b64++); signed char code; if (c >= GPR_ARRAY_SIZE(base64_bytes)) continue; if (url_safe) { @@ -214,7 +214,7 @@ grpc_slice grpc_base64_decode_with_len(const char* b64, size_t b64_len, goto fail; } } else { - codes[num_codes++] = (unsigned char)code; + codes[num_codes++] = static_cast<unsigned char>(code); if (num_codes == 4) { if (!decode_group(codes, num_codes, current, &result_size)) goto fail; num_codes = 0; diff --git a/src/core/lib/slice/percent_encoding.cc b/src/core/lib/slice/percent_encoding.cc index 894e43b191..84fb554454 100644 --- a/src/core/lib/slice/percent_encoding.cc +++ b/src/core/lib/slice/percent_encoding.cc @@ -78,9 +78,9 @@ static bool valid_hex(const uint8_t* p, const uint8_t* end) { } static uint8_t dehex(uint8_t c) { - if (c >= '0' && c <= '9') return (uint8_t)(c - '0'); - if (c >= 'A' && c <= 'F') return (uint8_t)(c - 'A' + 10); - if (c >= 'a' && c <= 'f') return (uint8_t)(c - 'a' + 10); + if (c >= '0' && c <= '9') return static_cast<uint8_t>(c - '0'); + if (c >= 'A' && c <= 'F') return static_cast<uint8_t>(c - 'A' + 10); + if (c >= 'a' && c <= 'f') return static_cast<uint8_t>(c - 'a' + 10); GPR_UNREACHABLE_CODE(return 255); } @@ -114,7 +114,7 @@ bool grpc_strict_percent_decode_slice(grpc_slice slice_in, uint8_t* q = GRPC_SLICE_START_PTR(*slice_out); while (p != in_end) { if (*p == '%') { - *q++ = (uint8_t)(dehex(p[1]) << 4) | (dehex(p[2])); + *q++ = static_cast<uint8_t>(dehex(p[1]) << 4) | (dehex(p[2])); p += 3; } else { *q++ = *p++; @@ -155,7 +155,7 @@ grpc_slice grpc_permissive_percent_decode_slice(grpc_slice slice_in) { if (!valid_hex(p + 1, in_end) || !valid_hex(p + 2, in_end)) { *q++ = *p++; } else { - *q++ = (uint8_t)(dehex(p[1]) << 4) | (dehex(p[2])); + *q++ = static_cast<uint8_t>(dehex(p[1]) << 4) | (dehex(p[2])); p += 3; } } else { diff --git a/src/core/lib/slice/slice.cc b/src/core/lib/slice/slice.cc index 1eb15290eb..136cce1d1e 100644 --- a/src/core/lib/slice/slice.cc +++ b/src/core/lib/slice/slice.cc @@ -27,7 +27,7 @@ #include "src/core/lib/iomgr/exec_ctx.h" char* grpc_slice_to_c_string(grpc_slice slice) { - char* out = (char*)gpr_malloc(GRPC_SLICE_LENGTH(slice) + 1); + char* out = static_cast<char*>(gpr_malloc(GRPC_SLICE_LENGTH(slice) + 1)); memcpy(out, GRPC_SLICE_START_PTR(slice), GRPC_SLICE_LENGTH(slice)); out[GRPC_SLICE_LENGTH(slice)] = 0; return out; @@ -104,12 +104,12 @@ typedef struct new_slice_refcount { } new_slice_refcount; static void new_slice_ref(void* p) { - new_slice_refcount* r = (new_slice_refcount*)p; + new_slice_refcount* r = static_cast<new_slice_refcount*>(p); gpr_ref(&r->refs); } static void new_slice_unref(void* p) { - new_slice_refcount* r = (new_slice_refcount*)p; + new_slice_refcount* r = static_cast<new_slice_refcount*>(p); if (gpr_unref(&r->refs)) { r->user_destroy(r->user_data); gpr_free(r); @@ -125,7 +125,7 @@ grpc_slice grpc_slice_new_with_user_data(void* p, size_t len, void* user_data) { grpc_slice slice; new_slice_refcount* rc = - (new_slice_refcount*)gpr_malloc(sizeof(new_slice_refcount)); + static_cast<new_slice_refcount*>(gpr_malloc(sizeof(new_slice_refcount))); gpr_ref_init(&rc->refs, 1); rc->rc.vtable = &new_slice_vtable; rc->rc.sub_refcount = &rc->rc; @@ -133,7 +133,7 @@ grpc_slice grpc_slice_new_with_user_data(void* p, size_t len, rc->user_data = user_data; slice.refcount = &rc->rc; - slice.data.refcounted.bytes = (uint8_t*)p; + slice.data.refcounted.bytes = static_cast<uint8_t*>(p); slice.data.refcounted.length = len; return slice; } @@ -154,12 +154,12 @@ typedef struct new_with_len_slice_refcount { } new_with_len_slice_refcount; static void new_with_len_ref(void* p) { - new_with_len_slice_refcount* r = (new_with_len_slice_refcount*)p; + new_with_len_slice_refcount* r = static_cast<new_with_len_slice_refcount*>(p); gpr_ref(&r->refs); } static void new_with_len_unref(void* p) { - new_with_len_slice_refcount* r = (new_with_len_slice_refcount*)p; + new_with_len_slice_refcount* r = static_cast<new_with_len_slice_refcount*>(p); if (gpr_unref(&r->refs)) { r->user_destroy(r->user_data, r->user_length); gpr_free(r); @@ -173,8 +173,8 @@ static const grpc_slice_refcount_vtable new_with_len_vtable = { grpc_slice grpc_slice_new_with_len(void* p, size_t len, void (*destroy)(void*, size_t)) { grpc_slice slice; - new_with_len_slice_refcount* rc = (new_with_len_slice_refcount*)gpr_malloc( - sizeof(new_with_len_slice_refcount)); + new_with_len_slice_refcount* rc = static_cast<new_with_len_slice_refcount*>(gpr_malloc( + sizeof(new_with_len_slice_refcount))); gpr_ref_init(&rc->refs, 1); rc->rc.vtable = &new_with_len_vtable; rc->rc.sub_refcount = &rc->rc; @@ -183,7 +183,7 @@ grpc_slice grpc_slice_new_with_len(void* p, size_t len, rc->user_length = len; slice.refcount = &rc->rc; - slice.data.refcounted.bytes = (uint8_t*)p; + slice.data.refcounted.bytes = static_cast<uint8_t*>(p); slice.data.refcounted.length = len; return slice; } @@ -205,12 +205,12 @@ typedef struct { } malloc_refcount; static void malloc_ref(void* p) { - malloc_refcount* r = (malloc_refcount*)p; + malloc_refcount* r = static_cast<malloc_refcount*>(p); gpr_ref(&r->refs); } static void malloc_unref(void* p) { - malloc_refcount* r = (malloc_refcount*)p; + malloc_refcount* r = static_cast<malloc_refcount*>(p); if (gpr_unref(&r->refs)) { gpr_free(r); } @@ -233,7 +233,7 @@ grpc_slice grpc_slice_malloc_large(size_t length) { bytes is an array of bytes of the requested length Both parts are placed in the same allocation returned from gpr_malloc */ malloc_refcount* rc = - (malloc_refcount*)gpr_malloc(sizeof(malloc_refcount) + length); + static_cast<malloc_refcount*>(gpr_malloc(sizeof(malloc_refcount) + length)); /* Initial refcount on rc is 1 - and it's up to the caller to release this reference. */ @@ -246,7 +246,7 @@ grpc_slice grpc_slice_malloc_large(size_t length) { /* The slices refcount points back to the allocated block. */ slice.refcount = &rc->base; /* The data bytes are placed immediately after the refcount struct */ - slice.data.refcounted.bytes = (uint8_t*)(rc + 1); + slice.data.refcounted.bytes = reinterpret_cast<uint8_t*>(rc + 1); /* And the length of the block is set to the requested length */ slice.data.refcounted.length = length; return slice; @@ -260,7 +260,7 @@ grpc_slice grpc_slice_malloc(size_t length) { } else { /* small slice: just inline the data */ slice.refcount = nullptr; - slice.data.inlined.length = (uint8_t)length; + slice.data.inlined.length = static_cast<uint8_t>(length); } return slice; } @@ -283,7 +283,7 @@ grpc_slice grpc_slice_sub_no_ref(grpc_slice source, size_t begin, size_t end) { /* Enforce preconditions */ GPR_ASSERT(source.data.inlined.length >= end); subset.refcount = nullptr; - subset.data.inlined.length = (uint8_t)(end - begin); + subset.data.inlined.length = static_cast<uint8_t>(end - begin); memcpy(subset.data.inlined.bytes, source.data.inlined.bytes + begin, end - begin); } @@ -295,7 +295,7 @@ grpc_slice grpc_slice_sub(grpc_slice source, size_t begin, size_t end) { if (end - begin <= sizeof(subset.data.inlined.bytes)) { subset.refcount = nullptr; - subset.data.inlined.length = (uint8_t)(end - begin); + subset.data.inlined.length = static_cast<uint8_t>(end - begin); memcpy(subset.data.inlined.bytes, GRPC_SLICE_START_PTR(source) + begin, end - begin); } else { @@ -314,10 +314,10 @@ grpc_slice grpc_slice_split_tail_maybe_ref(grpc_slice* source, size_t split, /* inlined data, copy it out */ GPR_ASSERT(source->data.inlined.length >= split); tail.refcount = nullptr; - tail.data.inlined.length = (uint8_t)(source->data.inlined.length - split); + tail.data.inlined.length = static_cast<uint8_t>(source->data.inlined.length - split); memcpy(tail.data.inlined.bytes, source->data.inlined.bytes + split, tail.data.inlined.length); - source->data.inlined.length = (uint8_t)split; + source->data.inlined.length = static_cast<uint8_t>(split); } else { size_t tail_length = source->data.refcounted.length - split; GPR_ASSERT(source->data.refcounted.length >= split); @@ -325,7 +325,7 @@ grpc_slice grpc_slice_split_tail_maybe_ref(grpc_slice* source, size_t split, ref_whom != GRPC_SLICE_REF_TAIL) { /* Copy out the bytes - it'll be cheaper than refcounting */ tail.refcount = nullptr; - tail.data.inlined.length = (uint8_t)tail_length; + tail.data.inlined.length = static_cast<uint8_t>(tail_length); memcpy(tail.data.inlined.bytes, source->data.refcounted.bytes + split, tail_length); source->refcount = source->refcount->sub_refcount; @@ -368,17 +368,17 @@ grpc_slice grpc_slice_split_head(grpc_slice* source, size_t split) { GPR_ASSERT(source->data.inlined.length >= split); head.refcount = nullptr; - head.data.inlined.length = (uint8_t)split; + head.data.inlined.length = static_cast<uint8_t>(split); memcpy(head.data.inlined.bytes, source->data.inlined.bytes, split); source->data.inlined.length = - (uint8_t)(source->data.inlined.length - split); + static_cast<uint8_t>(source->data.inlined.length - split); memmove(source->data.inlined.bytes, source->data.inlined.bytes + split, source->data.inlined.length); } else if (split < sizeof(head.data.inlined.bytes)) { GPR_ASSERT(source->data.refcounted.length >= split); head.refcount = nullptr; - head.data.inlined.length = (uint8_t)split; + head.data.inlined.length = static_cast<uint8_t>(split); memcpy(head.data.inlined.bytes, source->data.refcounted.bytes, split); source->refcount = source->refcount->sub_refcount; source->data.refcounted.bytes += split; @@ -416,7 +416,7 @@ int grpc_slice_eq(grpc_slice a, grpc_slice b) { } int grpc_slice_cmp(grpc_slice a, grpc_slice b) { - int d = (int)(GRPC_SLICE_LENGTH(a) - GRPC_SLICE_LENGTH(b)); + int d = static_cast<int>(GRPC_SLICE_LENGTH(a) - GRPC_SLICE_LENGTH(b)); if (d != 0) return d; return memcmp(GRPC_SLICE_START_PTR(a), GRPC_SLICE_START_PTR(b), GRPC_SLICE_LENGTH(a)); @@ -424,7 +424,7 @@ int grpc_slice_cmp(grpc_slice a, grpc_slice b) { int grpc_slice_str_cmp(grpc_slice a, const char* b) { size_t b_length = strlen(b); - int d = (int)(GRPC_SLICE_LENGTH(a) - b_length); + int d = static_cast<int>(GRPC_SLICE_LENGTH(a) - b_length); if (d != 0) return d; return memcmp(GRPC_SLICE_START_PTR(a), b, b_length); } @@ -443,17 +443,17 @@ int grpc_slice_buf_start_eq(grpc_slice a, const void* b, size_t len) { } int grpc_slice_rchr(grpc_slice s, char c) { - const char* b = (const char*)GRPC_SLICE_START_PTR(s); + const char* b = reinterpret_cast<const char*>GRPC_SLICE_START_PTR(s); int i; - for (i = (int)GRPC_SLICE_LENGTH(s) - 1; i != -1 && b[i] != c; i--) + for (i = static_cast<int>GRPC_SLICE_LENGTH(s) - 1; i != -1 && b[i] != c; i--) ; return i; } int grpc_slice_chr(grpc_slice s, char c) { - const char* b = (const char*)GRPC_SLICE_START_PTR(s); - const char* p = (const char*)memchr(b, c, GRPC_SLICE_LENGTH(s)); - return p == nullptr ? -1 : (int)(p - b); + const char* b = reinterpret_cast<const char*>GRPC_SLICE_START_PTR(s); + const char* p = static_cast<const char*>(memchr(b, c, GRPC_SLICE_LENGTH(s))); + return p == nullptr ? -1 : static_cast<int>(p - b); } int grpc_slice_slice(grpc_slice haystack, grpc_slice needle) { @@ -466,12 +466,12 @@ int grpc_slice_slice(grpc_slice haystack, grpc_slice needle) { if (haystack_len < needle_len) return -1; if (haystack_len == needle_len) return grpc_slice_eq(haystack, needle) ? 0 : -1; - if (needle_len == 1) return grpc_slice_chr(haystack, (char)*needle_bytes); + if (needle_len == 1) return grpc_slice_chr(haystack, static_cast<char>(*needle_bytes)); const uint8_t* last = haystack_bytes + haystack_len - needle_len; for (const uint8_t* cur = haystack_bytes; cur != last; ++cur) { if (0 == memcmp(cur, needle_bytes, needle_len)) { - return (int)(cur - haystack_bytes); + return static_cast<int>(cur - haystack_bytes); } } return -1; diff --git a/src/core/lib/slice/slice_buffer.cc b/src/core/lib/slice/slice_buffer.cc index 178c7f9e94..84a2b5f6d9 100644 --- a/src/core/lib/slice/slice_buffer.cc +++ b/src/core/lib/slice/slice_buffer.cc @@ -32,7 +32,7 @@ static void maybe_embiggen(grpc_slice_buffer* sb) { /* How far away from sb->base_slices is sb->slices pointer */ - size_t slice_offset = (size_t)(sb->slices - sb->base_slices); + size_t slice_offset = static_cast<size_t>(sb->slices - sb->base_slices); size_t slice_count = sb->count + slice_offset; if (slice_count == sb->capacity) { @@ -46,11 +46,11 @@ static void maybe_embiggen(grpc_slice_buffer* sb) { GPR_ASSERT(sb->capacity > slice_count); if (sb->base_slices == sb->inlined) { sb->base_slices = - (grpc_slice*)gpr_malloc(sb->capacity * sizeof(grpc_slice)); + static_cast<grpc_slice*>(gpr_malloc(sb->capacity * sizeof(grpc_slice))); memcpy(sb->base_slices, sb->inlined, slice_count * sizeof(grpc_slice)); } else { - sb->base_slices = (grpc_slice*)gpr_realloc( - sb->base_slices, sb->capacity * sizeof(grpc_slice)); + sb->base_slices = static_cast<grpc_slice*>(gpr_realloc( + sb->base_slices, sb->capacity * sizeof(grpc_slice))); } sb->slices = sb->base_slices + slice_offset; @@ -89,7 +89,7 @@ uint8_t* grpc_slice_buffer_tiny_add(grpc_slice_buffer* sb, size_t n) { if ((back->data.inlined.length + n) > sizeof(back->data.inlined.bytes)) goto add_new; out = back->data.inlined.bytes + back->data.inlined.length; - back->data.inlined.length = (uint8_t)(back->data.inlined.length + n); + back->data.inlined.length = static_cast<uint8_t>(back->data.inlined.length + n); return out; add_new: @@ -97,7 +97,7 @@ add_new: back = &sb->slices[sb->count]; sb->count++; back->refcount = nullptr; - back->data.inlined.length = (uint8_t)n; + back->data.inlined.length = static_cast<uint8_t>(n); return back->data.inlined.bytes; } @@ -126,7 +126,7 @@ void grpc_slice_buffer_add(grpc_slice_buffer* sb, grpc_slice s) { memcpy(back->data.inlined.bytes + back->data.inlined.length, s.data.inlined.bytes, s.data.inlined.length); back->data.inlined.length = - (uint8_t)(back->data.inlined.length + s.data.inlined.length); + static_cast<uint8_t>(back->data.inlined.length + s.data.inlined.length); } else { size_t cp1 = GRPC_SLICE_INLINED_SIZE - back->data.inlined.length; memcpy(back->data.inlined.bytes + back->data.inlined.length, @@ -136,7 +136,7 @@ void grpc_slice_buffer_add(grpc_slice_buffer* sb, grpc_slice s) { back = &sb->slices[n]; sb->count = n + 1; back->refcount = nullptr; - back->data.inlined.length = (uint8_t)(s.data.inlined.length - cp1); + back->data.inlined.length = static_cast<uint8_t>(s.data.inlined.length - cp1); memcpy(back->data.inlined.bytes, s.data.inlined.bytes + cp1, s.data.inlined.length - cp1); } @@ -177,8 +177,8 @@ void grpc_slice_buffer_reset_and_unref(grpc_slice_buffer* sb) { } void grpc_slice_buffer_swap(grpc_slice_buffer* a, grpc_slice_buffer* b) { - size_t a_offset = (size_t)(a->slices - a->base_slices); - size_t b_offset = (size_t)(b->slices - b->base_slices); + size_t a_offset = static_cast<size_t>(a->slices - a->base_slices); + size_t b_offset = static_cast<size_t>(b->slices - b->base_slices); size_t a_count = a->count + a_offset; size_t b_count = b->count + b_offset; @@ -287,7 +287,7 @@ void grpc_slice_buffer_move_first_no_ref(grpc_slice_buffer* src, size_t n, void grpc_slice_buffer_move_first_into_buffer(grpc_slice_buffer* src, size_t n, void* dst) { - char* dstp = (char*)dst; + char* dstp = static_cast<char*>(dst); GPR_ASSERT(src->length >= n); while (n > 0) { diff --git a/src/core/lib/slice/slice_hash_table.cc b/src/core/lib/slice/slice_hash_table.cc index 89340eff84..1818b126ca 100644 --- a/src/core/lib/slice/slice_hash_table.cc +++ b/src/core/lib/slice/slice_hash_table.cc @@ -60,14 +60,14 @@ grpc_slice_hash_table* grpc_slice_hash_table_create( size_t num_entries, grpc_slice_hash_table_entry* entries, void (*destroy_value)(void* value), int (*value_cmp)(void* a, void* b)) { grpc_slice_hash_table* table = - (grpc_slice_hash_table*)gpr_zalloc(sizeof(*table)); + static_cast<grpc_slice_hash_table*>(gpr_zalloc(sizeof(*table))); gpr_ref_init(&table->refs, 1); table->destroy_value = destroy_value; table->value_cmp = value_cmp; // Keep load factor low to improve performance of lookups. table->size = num_entries * 2; const size_t entry_size = sizeof(grpc_slice_hash_table_entry) * table->size; - table->entries = (grpc_slice_hash_table_entry*)gpr_zalloc(entry_size); + table->entries = static_cast<grpc_slice_hash_table_entry*>(gpr_zalloc(entry_size)); for (size_t i = 0; i < num_entries; ++i) { grpc_slice_hash_table_entry* entry = &entries[i]; grpc_slice_hash_table_add(table, entry->key, entry->value); diff --git a/src/core/lib/slice/slice_intern.cc b/src/core/lib/slice/slice_intern.cc index cf471f30f8..f4aad73e0f 100644 --- a/src/core/lib/slice/slice_intern.cc +++ b/src/core/lib/slice/slice_intern.cc @@ -70,7 +70,7 @@ static uint32_t max_static_metadata_hash_probe; static uint32_t static_metadata_hash_values[GRPC_STATIC_MDSTR_COUNT]; static void interned_slice_ref(void* p) { - interned_slice_refcount* s = (interned_slice_refcount*)p; + interned_slice_refcount* s = static_cast<interned_slice_refcount*>(p); GPR_ASSERT(gpr_atm_no_barrier_fetch_add(&s->refcnt, 1) > 0); } @@ -91,22 +91,22 @@ static void interned_slice_destroy(interned_slice_refcount* s) { } static void interned_slice_unref(void* p) { - interned_slice_refcount* s = (interned_slice_refcount*)p; + interned_slice_refcount* s = static_cast<interned_slice_refcount*>(p); if (1 == gpr_atm_full_fetch_add(&s->refcnt, -1)) { interned_slice_destroy(s); } } static void interned_slice_sub_ref(void* p) { - interned_slice_ref(((char*)p) - offsetof(interned_slice_refcount, sub)); + interned_slice_ref((static_cast<char*>(p)) - offsetof(interned_slice_refcount, sub)); } static void interned_slice_sub_unref(void* p) { - interned_slice_unref(((char*)p) - offsetof(interned_slice_refcount, sub)); + interned_slice_unref((static_cast<char*>(p)) - offsetof(interned_slice_refcount, sub)); } static uint32_t interned_slice_hash(grpc_slice slice) { - interned_slice_refcount* s = (interned_slice_refcount*)slice.refcount; + interned_slice_refcount* s = reinterpret_cast<interned_slice_refcount*>(slice.refcount); return s->hash; } @@ -129,8 +129,8 @@ static void grow_shard(slice_shard* shard) { interned_slice_refcount** strtab; interned_slice_refcount *s, *next; - strtab = (interned_slice_refcount**)gpr_zalloc( - sizeof(interned_slice_refcount*) * capacity); + strtab = static_cast<interned_slice_refcount**>(gpr_zalloc( + sizeof(interned_slice_refcount*) * capacity)); for (i = 0; i < shard->capacity; i++) { for (s = shard->strs[i]; s; s = next) { @@ -148,7 +148,7 @@ static void grow_shard(slice_shard* shard) { static grpc_slice materialize(interned_slice_refcount* s) { grpc_slice slice; slice.refcount = &s->base; - slice.data.refcounted.bytes = (uint8_t*)(s + 1); + slice.data.refcounted.bytes = reinterpret_cast<uint8_t*>(s + 1); slice.data.refcounted.length = s->length; return slice; } @@ -237,8 +237,8 @@ grpc_slice grpc_slice_intern(grpc_slice slice) { /* not found: create a new string */ /* string data goes after the internal_string header */ - s = (interned_slice_refcount*)gpr_malloc(sizeof(*s) + - GRPC_SLICE_LENGTH(slice)); + s = static_cast<interned_slice_refcount*>(gpr_malloc(sizeof(*s) + + GRPC_SLICE_LENGTH(slice))); gpr_atm_rel_store(&s->refcnt, 1); s->length = GRPC_SLICE_LENGTH(slice); s->hash = hash; @@ -268,15 +268,15 @@ void grpc_test_only_set_slice_hash_seed(uint32_t seed) { void grpc_slice_intern_init(void) { if (!g_forced_hash_seed) { - g_hash_seed = (uint32_t)gpr_now(GPR_CLOCK_REALTIME).tv_nsec; + g_hash_seed = static_cast<uint32_t>(gpr_now(GPR_CLOCK_REALTIME).tv_nsec); } for (size_t i = 0; i < SHARD_COUNT; i++) { slice_shard* shard = &g_shards[i]; gpr_mu_init(&shard->mu); shard->count = 0; shard->capacity = INITIAL_SHARD_CAPACITY; - shard->strs = (interned_slice_refcount**)gpr_zalloc(sizeof(*shard->strs) * - shard->capacity); + shard->strs = static_cast<interned_slice_refcount**>(gpr_zalloc(sizeof(*shard->strs) * + shard->capacity)); } for (size_t i = 0; i < GPR_ARRAY_SIZE(static_metadata_hash); i++) { static_metadata_hash[i].hash = 0; @@ -291,9 +291,9 @@ void grpc_slice_intern_init(void) { GPR_ARRAY_SIZE(static_metadata_hash); if (static_metadata_hash[slot].idx == GRPC_STATIC_MDSTR_COUNT) { static_metadata_hash[slot].hash = static_metadata_hash_values[i]; - static_metadata_hash[slot].idx = (uint32_t)i; + static_metadata_hash[slot].idx = static_cast<uint32_t>(i); if (j > max_static_metadata_hash_probe) { - max_static_metadata_hash_probe = (uint32_t)j; + max_static_metadata_hash_probe = static_cast<uint32_t>(j); } break; } diff --git a/src/core/lib/slice/slice_string_helpers.cc b/src/core/lib/slice/slice_string_helpers.cc index 4441a26d8e..2015040c12 100644 --- a/src/core/lib/slice/slice_string_helpers.cc +++ b/src/core/lib/slice/slice_string_helpers.cc @@ -26,7 +26,7 @@ #include "src/core/lib/slice/slice_internal.h" char* grpc_dump_slice(grpc_slice s, uint32_t flags) { - return gpr_dump((const char*)GRPC_SLICE_START_PTR(s), GRPC_SLICE_LENGTH(s), + return gpr_dump(reinterpret_cast<const char*>GRPC_SLICE_START_PTR(s), GRPC_SLICE_LENGTH(s), flags); } @@ -110,6 +110,6 @@ void grpc_slice_split_without_space(grpc_slice str, const char* sep, } bool grpc_parse_slice_to_uint32(grpc_slice str, uint32_t* result) { - return gpr_parse_bytes_to_uint32((const char*)GRPC_SLICE_START_PTR(str), + return gpr_parse_bytes_to_uint32(reinterpret_cast<const char*>GRPC_SLICE_START_PTR(str), GRPC_SLICE_LENGTH(str), result) != 0; } |