Skip to content

Commit 24d1b49

Browse files
etrclaude
andcommitted
TASK-056: simplify reject_terminus_collision
Address two code-simplifier majors carried in the unworked review report for TASK-056: - Remove the `opposite_is_prefix` alias variable; derive the `existing_kind` string from `want_is_prefix` directly with the inverse ternary. - Collapse the two-step `collision = true` if/else-if pattern in the `want_is_prefix=true` branch into a single boolean expression, making the symmetry with the `!want_is_prefix` branch visible and letting `collision` be `const`. No behaviour change. routing_regression (26/26, 99 checks) and webserver_register_path_prefix (19/19, 38 checks) still green. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 09c4dcc commit 24d1b49

1 file changed

Lines changed: 6 additions & 19 deletions

File tree

src/detail/webserver_routes.cpp

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -220,27 +220,14 @@ void webserver_impl::reject_terminus_collision(const std::string& key,
220220
// Throws BEFORE any mutation so the atomicity guarantee pinned by
221221
// upsert_param_route_failed_duplicate_leaves_original_intact holds
222222
// for the new throw too.
223-
const bool opposite_is_prefix = !want_is_prefix;
224-
bool collision = false;
225-
if (!want_is_prefix) {
226-
// New exact entry: opposite kind is prefix. The only prefix
227-
// storage is the radix prefix_terminus_.
228-
collision = param_and_prefix_routes_.has_terminus_at(
229-
key, /*is_prefix=*/true);
230-
} else {
231-
// New prefix entry: opposite kind is exact. Exact entries live
232-
// in exact_routes_ (unparameterized) and in the radix tree's
233-
// exact_terminus_ (parameterized). Probe both.
234-
if (exact_routes_.find(key) != exact_routes_.end()) {
235-
collision = true;
236-
} else if (param_and_prefix_routes_.has_terminus_at(
237-
key, /*is_prefix=*/false)) {
238-
collision = true;
239-
}
240-
}
223+
const bool collision = !want_is_prefix
224+
? param_and_prefix_routes_.has_terminus_at(key, /*is_prefix=*/true)
225+
: (exact_routes_.find(key) != exact_routes_.end()
226+
|| param_and_prefix_routes_.has_terminus_at(
227+
key, /*is_prefix=*/false));
241228
if (collision) {
242229
const char* incoming_kind = want_is_prefix ? "prefix" : "exact";
243-
const char* existing_kind = opposite_is_prefix ? "prefix" : "exact";
230+
const char* existing_kind = want_is_prefix ? "exact" : "prefix";
244231
throw std::invalid_argument(
245232
"Path '" + key + "' is already registered as a "
246233
+ std::string(existing_kind)

0 commit comments

Comments
 (0)