Skip to content

Commit

Permalink
adds curly brackets following if clauses making the code subjectively…
Browse files Browse the repository at this point in the history
… clearer (#615)
  • Loading branch information
lemire authored Mar 20, 2024
1 parent 2f8d86e commit 4b963d0
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 22 deletions.
8 changes: 5 additions & 3 deletions include/ada/common_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
12 changes: 9 additions & 3 deletions include/ada/url_search_params-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,20 +194,26 @@ inline bool url_search_params_iter<T, Type>::has_next() {

template <>
inline std::optional<std::string_view> 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<std::string_view> 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<key_value_view_pair>
url_search_params_entries_iter::next() {
if (!has_next()) return std::nullopt;
if (!has_next()) {
return std::nullopt;
}
return params.params[pos++];
}

Expand Down
63 changes: 47 additions & 16 deletions src/ada_c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<ada::url_search_params>& r =
*(ada::result<ada::url_search_params>*)result;
if (!r) return 0;
if (!r) {
return 0;
}
return r->size();
}

void ada_search_params_sort(ada_url_search_params result) {
ada::result<ada::url_search_params>& r =
*(ada::result<ada::url_search_params>*)result;
if (r) r->sort();
if (r) {
r->sort();
}
}

void ada_search_params_append(ada_url_search_params result, const char* key,
Expand Down Expand Up @@ -549,7 +553,9 @@ bool ada_search_params_has(ada_url_search_params result, const char* key,
size_t key_length) {
ada::result<ada::url_search_params>& r =
*(ada::result<ada::url_search_params>*)result;
if (!r) return false;
if (!r) {
return false;
}
return r->has(std::string_view(key, key_length));
}

Expand All @@ -558,7 +564,9 @@ bool ada_search_params_has_value(ada_url_search_params result, const char* key,
size_t value_length) {
ada::result<ada::url_search_params>& r =
*(ada::result<ada::url_search_params>*)result;
if (!r) return false;
if (!r) {
return false;
}
return r->has(std::string_view(key, key_length),
std::string_view(value, value_length));
}
Expand All @@ -567,9 +575,13 @@ ada_string ada_search_params_get(ada_url_search_params result, const char* key,
size_t key_length) {
ada::result<ada::url_search_params>& r =
*(ada::result<ada::url_search_params>*)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());
}

Expand Down Expand Up @@ -627,14 +639,18 @@ void ada_free_strings(ada_strings result) {
size_t ada_strings_size(ada_strings result) {
ada::result<std::vector<std::string>>* r =
(ada::result<std::vector<std::string>>*)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<std::vector<std::string>>* r =
(ada::result<std::vector<std::string>>*)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());
}
Expand All @@ -649,17 +665,23 @@ ada_string ada_search_params_keys_iter_next(
ada_url_search_params_keys_iter result) {
ada::result<ada::url_search_params_keys_iter>* r =
(ada::result<ada::url_search_params_keys_iter>*)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());
}

bool ada_search_params_keys_iter_has_next(
ada_url_search_params_keys_iter result) {
ada::result<ada::url_search_params_keys_iter>* r =
(ada::result<ada::url_search_params_keys_iter>*)result;
if (!r) return false;
if (!r) {
return false;
}
return (*r)->has_next();
}

Expand All @@ -674,17 +696,23 @@ ada_string ada_search_params_values_iter_next(
ada_url_search_params_values_iter result) {
ada::result<ada::url_search_params_values_iter>* r =
(ada::result<ada::url_search_params_values_iter>*)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());
}

bool ada_search_params_values_iter_has_next(
ada_url_search_params_values_iter result) {
ada::result<ada::url_search_params_values_iter>* r =
(ada::result<ada::url_search_params_values_iter>*)result;
if (!r) return false;
if (!r) {
return false;
}
return (*r)->has_next();
}

Expand All @@ -701,8 +729,9 @@ ada_string_pair ada_search_params_entries_iter_next(
(ada::result<ada::url_search_params_entries_iter>*)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())};
Expand All @@ -712,7 +741,9 @@ bool ada_search_params_entries_iter_has_next(
ada_url_search_params_entries_iter result) {
ada::result<ada::url_search_params_entries_iter>* r =
(ada::result<ada::url_search_params_entries_iter>*)result;
if (!r) return false;
if (!r) {
return false;
}
return (*r)->has_next();
}

Expand Down

0 comments on commit 4b963d0

Please sign in to comment.