From 7426a31201e8973276cdabd2da4fcaaa3cd3ac0f Mon Sep 17 00:00:00 2001 From: Daniel Lemire Date: Wed, 20 Mar 2024 08:49:36 -0400 Subject: [PATCH] adds curly brackets following if clauses making the code subjectively clearer --- include/ada/common_defs.h | 8 ++-- include/ada/url_search_params-inl.h | 12 ++++-- src/ada_c.cpp | 63 +++++++++++++++++++++-------- 3 files changed, 61 insertions(+), 22 deletions(-) diff --git a/include/ada/common_defs.h b/include/ada/common_defs.h index 8aacdb56d..cefed4edf 100644 --- a/include/ada/common_defs.h +++ b/include/ada/common_defs.h @@ -280,9 +280,11 @@ namespace ada { #ifdef ADA_VISUAL_STUDIO #define ADA_ASSUME(COND) __assume(COND) #else -#define ADA_ASSUME(COND) \ - do { \ - if (!(COND)) __builtin_unreachable(); \ +#define ADA_ASSUME(COND) \ + do { \ + if (!(COND)) { \ + __builtin_unreachable(); \ + } \ } while (0) #endif diff --git a/include/ada/url_search_params-inl.h b/include/ada/url_search_params-inl.h index 776f30814..0b7d00f64 100644 --- a/include/ada/url_search_params-inl.h +++ b/include/ada/url_search_params-inl.h @@ -194,20 +194,26 @@ inline bool url_search_params_iter::has_next() { template <> inline std::optional url_search_params_keys_iter::next() { - if (!has_next()) return std::nullopt; + if (!has_next()) { + return std::nullopt; + } return params.params[pos++].first; } template <> inline std::optional url_search_params_values_iter::next() { - if (!has_next()) return std::nullopt; + if (!has_next()) { + return std::nullopt; + } return params.params[pos++].second; } template <> inline std::optional url_search_params_entries_iter::next() { - if (!has_next()) return std::nullopt; + if (!has_next()) { + return std::nullopt; + } return params.params[pos++]; } diff --git a/src/ada_c.cpp b/src/ada_c.cpp index 751c29766..d3da77493 100644 --- a/src/ada_c.cpp +++ b/src/ada_c.cpp @@ -493,14 +493,18 @@ ada_owned_string ada_search_params_to_string(ada_url_search_params result) { size_t ada_search_params_size(ada_url_search_params result) { ada::result& r = *(ada::result*)result; - if (!r) return 0; + if (!r) { + return 0; + } return r->size(); } void ada_search_params_sort(ada_url_search_params result) { ada::result& r = *(ada::result*)result; - if (r) r->sort(); + if (r) { + r->sort(); + } } void ada_search_params_append(ada_url_search_params result, const char* key, @@ -549,7 +553,9 @@ bool ada_search_params_has(ada_url_search_params result, const char* key, size_t key_length) { ada::result& r = *(ada::result*)result; - if (!r) return false; + if (!r) { + return false; + } return r->has(std::string_view(key, key_length)); } @@ -558,7 +564,9 @@ bool ada_search_params_has_value(ada_url_search_params result, const char* key, size_t value_length) { ada::result& r = *(ada::result*)result; - if (!r) return false; + if (!r) { + return false; + } return r->has(std::string_view(key, key_length), std::string_view(value, value_length)); } @@ -567,9 +575,13 @@ ada_string ada_search_params_get(ada_url_search_params result, const char* key, size_t key_length) { ada::result& r = *(ada::result*)result; - if (!r) return ada_string_create(NULL, 0); + if (!r) { + return ada_string_create(NULL, 0); + } auto found = r->get(std::string_view(key, key_length)); - if (!found.has_value()) return ada_string_create(NULL, 0); + if (!found.has_value()) { + return ada_string_create(NULL, 0); + } return ada_string_create(found->data(), found->length()); } @@ -627,14 +639,18 @@ void ada_free_strings(ada_strings result) { size_t ada_strings_size(ada_strings result) { ada::result>* r = (ada::result>*)result; - if (!r) return 0; + if (!r) { + return 0; + } return (*r)->size(); } ada_string ada_strings_get(ada_strings result, size_t index) { ada::result>* r = (ada::result>*)result; - if (!r) return ada_string_create(NULL, 0); + if (!r) { + return ada_string_create(NULL, 0); + } std::string_view view = (*r)->at(index); return ada_string_create(view.data(), view.length()); } @@ -649,9 +665,13 @@ ada_string ada_search_params_keys_iter_next( ada_url_search_params_keys_iter result) { ada::result* r = (ada::result*)result; - if (!r) return ada_string_create(NULL, 0); + if (!r) { + return ada_string_create(NULL, 0); + } auto next = (*r)->next(); - if (!next.has_value()) return ada_string_create(NULL, 0); + if (!next.has_value()) { + return ada_string_create(NULL, 0); + } return ada_string_create(next->data(), next->length()); } @@ -659,7 +679,9 @@ bool ada_search_params_keys_iter_has_next( ada_url_search_params_keys_iter result) { ada::result* r = (ada::result*)result; - if (!r) return false; + if (!r) { + return false; + } return (*r)->has_next(); } @@ -674,9 +696,13 @@ ada_string ada_search_params_values_iter_next( ada_url_search_params_values_iter result) { ada::result* r = (ada::result*)result; - if (!r) return ada_string_create(NULL, 0); + if (!r) { + return ada_string_create(NULL, 0); + } auto next = (*r)->next(); - if (!next.has_value()) return ada_string_create(NULL, 0); + if (!next.has_value()) { + return ada_string_create(NULL, 0); + } return ada_string_create(next->data(), next->length()); } @@ -684,7 +710,9 @@ bool ada_search_params_values_iter_has_next( ada_url_search_params_values_iter result) { ada::result* r = (ada::result*)result; - if (!r) return false; + if (!r) { + return false; + } return (*r)->has_next(); } @@ -701,8 +729,9 @@ ada_string_pair ada_search_params_entries_iter_next( (ada::result*)result; if (!r) return {ada_string_create(NULL, 0), ada_string_create(NULL, 0)}; auto next = (*r)->next(); - if (!next.has_value()) + if (!next.has_value()) { return {ada_string_create(NULL, 0), ada_string_create(NULL, 0)}; + } return ada_string_pair{ ada_string_create(next->first.data(), next->first.length()), ada_string_create(next->second.data(), next->second.length())}; @@ -712,7 +741,9 @@ bool ada_search_params_entries_iter_has_next( ada_url_search_params_entries_iter result) { ada::result* r = (ada::result*)result; - if (!r) return false; + if (!r) { + return false; + } return (*r)->has_next(); }