Skip to content

Commit

Permalink
cleanup: heed abseil-string-find-startswith clang-tidy (#9416)
Browse files Browse the repository at this point in the history
Some downstream users enable this clang-tidy, so we might as well take
its advice.

https://clang.llvm.org/extra/clang-tidy/checks/abseil/string-find-startswith.html
  • Loading branch information
devbww authored Jul 2, 2022
1 parent c23bcf2 commit 6a7c0a8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 3 additions & 1 deletion google/cloud/pubsub/internal/exactly_once_policies.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#include "google/cloud/pubsub/internal/exactly_once_policies.h"
#include "absl/memory/memory.h"
#include "absl/strings/match.h"
#include <algorithm>

namespace google {
Expand Down Expand Up @@ -47,7 +48,8 @@ bool ExactlyOnceRetryPolicy::IsPermanentFailure(Status const& status) const {
if (ExactlyOnceRetryable(code)) return false;
auto const& metadata = status.error_info().metadata();
return !std::any_of(metadata.begin(), metadata.end(), [this](auto const& kv) {
return kv.first == ack_id_ && kv.second.rfind("TRANSIENT_FAILURE_", 0) == 0;
return kv.first == ack_id_ &&
absl::StartsWith(kv.second, "TRANSIENT_FAILURE_");
});
}

Expand Down
3 changes: 2 additions & 1 deletion google/cloud/pubsub/internal/extend_leases_with_retry.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "google/cloud/pubsub/internal/exactly_once_policies.h"
#include "google/cloud/completion_queue.h"
#include "google/cloud/log.h"
#include "absl/strings/match.h"
#include <algorithm>
#include <memory>

Expand All @@ -39,7 +40,7 @@ google::pubsub::v1::ModifyAckDeadlineRequest UpdateRequest(
auto const& m = status.error_info().metadata();
auto f = m.find(ack_id);
auto const permanent =
f == m.end() || f->second.rfind("TRANSIENT_FAILURE_", 0) != 0;
f == m.end() || !absl::StartsWith(f->second, "TRANSIENT_FAILURE_");
if (permanent) {
GCP_LOG(WARNING)
<< "permanent failure trying to extend the lease for ack_id="
Expand Down

0 comments on commit 6a7c0a8

Please sign in to comment.