diff options
author | Soheil Hassas Yeganeh <soheil@google.com> | 2018-10-18 15:49:42 -0400 |
---|---|---|
committer | Soheil Hassas Yeganeh <soheil@google.com> | 2018-10-18 16:04:20 -0400 |
commit | 3a9411ca1e733ce9f87b22136014c7a00bdeacbd (patch) | |
tree | 4ed040cb14b5ebb39f24837db6d70dc10e5090ff /src/core/lib/transport | |
parent | dfcc96227c6fe1a18068171c988cb0c5f1250f19 (diff) |
Optimize error handling for special cases.
This commit contains a few improvements:
1. Using a consequetive range of [0..4], will allow us to merge all
branches of error_is_special into one comparison.
2. With (1), we can remove the for loops to find entries in
error_status_map with a single O(1) lookup.
3. grpc_error_is_special() code paths should be inlined for ref
and unref to avoid callq for the majority of cases where speical
error is used.
4. grpc_error_get_int() should never accept a nullptr argument to
avoid an expensive branch in the hot path. Callers should all
allocate a dummy int on the stack when calling.
Diffstat (limited to 'src/core/lib/transport')
-rw-r--r-- | src/core/lib/transport/error_utils.cc | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/src/core/lib/transport/error_utils.cc b/src/core/lib/transport/error_utils.cc index 2eff8b2916..558f1d494c 100644 --- a/src/core/lib/transport/error_utils.cc +++ b/src/core/lib/transport/error_utils.cc @@ -26,8 +26,9 @@ static grpc_error* recursively_find_error_with_field(grpc_error* error, grpc_error_ints which) { + intptr_t unused; // If the error itself has a status code, return it. - if (grpc_error_get_int(error, which, nullptr)) { + if (grpc_error_get_int(error, which, &unused)) { return error; } if (grpc_error_is_special(error)) return nullptr; @@ -102,7 +103,8 @@ void grpc_error_get_status(grpc_error* error, grpc_millis deadline, } bool grpc_error_has_clear_grpc_status(grpc_error* error) { - if (grpc_error_get_int(error, GRPC_ERROR_INT_GRPC_STATUS, nullptr)) { + intptr_t unused; + if (grpc_error_get_int(error, GRPC_ERROR_INT_GRPC_STATUS, &unused)) { return true; } uint8_t slot = error->first_err; |