SolidWallOfCode commented on code in PR #9539:
URL: https://github.com/apache/trafficserver/pull/9539#discussion_r1142794649
##########
proxy/http/HttpTransact.cc:
##########
@@ -1971,11 +1971,11 @@ HttpTransact::OSDNSLookup(State *s)
action = s->http_config_param->redirect_actions_self_action;
TxnDebug("http_trans", "[OSDNSLookup] Self action - %d.", int(action));
} else {
- // Make sure the return value from contains is big enough for a void*.
- intptr_t x{intptr_t(RedirectEnabled::Action::INVALID)};
ink_release_assert(s->http_config_param->redirect_actions_map !=
nullptr);
-
ink_release_assert(s->http_config_param->redirect_actions_map->contains(s->dns_info.addr,
reinterpret_cast<void **>(&x)));
- action = static_cast<RedirectEnabled::Action>(x);
+ auto &addrs = *(s->http_config_param->redirect_actions_map);
+ auto spot = addrs.find(swoc::IPAddr(&s->dns_info.addr.sa));
+ ink_release_assert(spot != addrs.end()); // Should always find an entry.
+ action = std::get<1>(*spot);
Review Comment:
It's complicated. I initially used
```
auto && [ range, action ] = ...
```
but that shadowed an outer `action` and so didn't update appropriately. I
could have used
```
swoc::IPRange r;
std::tie(r, action) = ...
```
I decided the iterator style was reasonable primarily because at least it
was the most similar to the original code. With relation to the assert, for
ease of use reasons if the iterator is invalid
the range is bound to an invalid / empty range, which can be checked.
Therefore it could be done like
```
auto && [ range, action ] = ...find...
ink_release_assert(!range.empty());
```
and that would do the same thing as checking for `== end()`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]