Skip to content

Commit 370eabd

Browse files
committed
chore: clang-tidy fixes
1 parent ec4f063 commit 370eabd

File tree

2 files changed

+38
-40
lines changed

2 files changed

+38
-40
lines changed

google/cloud/bigtable/value.cc

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -344,12 +344,11 @@ bool Value::TypeAndArrayValuesMatch(google::bigtable::v2::Type const& type,
344344
if (!value.has_array_value()) {
345345
return false;
346346
}
347-
for (auto const& val : value.array_value().values()) {
348-
if (!TypeAndValuesMatch(type.array_type().element_type(), val)) {
349-
return false;
350-
}
351-
}
352-
return true;
347+
auto const& vals = value.array_value().values();
348+
// NOLINTNEXTLINE(misc-no-recursion)
349+
return std::all_of(vals.begin(), vals.end(), [&](auto const& val) -> bool {
350+
return TypeAndValuesMatch(type.array_type().element_type(), val);
351+
});
353352
}
354353

355354
// NOLINTNEXTLINE(misc-no-recursion)
@@ -360,18 +359,17 @@ bool Value::TypeAndMapValuesMatch(google::bigtable::v2::Type const& type,
360359
}
361360
auto key_type = type.map_type().key_type();
362361
auto value_type = type.map_type().value_type();
363-
for (auto const& val : value.array_value().values()) {
362+
auto const& vals = value.array_value().values();
363+
// NOLINTNEXTLINE(misc-no-recursion)
364+
return std::all_of(vals.begin(), vals.end(), [&](auto const& val) -> bool {
364365
if (!val.has_array_value() || val.array_value().values_size() != 2) {
365366
return false;
366367
}
367368
auto map_key = val.array_value().values(0);
368369
auto map_value = val.array_value().values(1);
369-
if (!TypeAndValuesMatch(key_type, map_key) ||
370-
!TypeAndValuesMatch(value_type, map_value)) {
371-
return false;
372-
}
373-
}
374-
return true;
370+
return TypeAndValuesMatch(key_type, map_key) &&
371+
TypeAndValuesMatch(value_type, map_value);
372+
});
375373
}
376374

377375
// NOLINTNEXTLINE(misc-no-recursion)

google/cloud/bigtable/value_test.cc

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1780,10 +1780,10 @@ TEST(Value, TypeAndValuesMatchNullScalar) {
17801780
}
17811781

17821782
TEST(Value, TypeAndValuesMatchArray) {
1783-
auto type = R"pb(
1783+
auto const* type = R"pb(
17841784
array_type { element_type { int64_type {} } }
17851785
)pb";
1786-
auto matching_value = R"pb(
1786+
auto const* matching_value = R"pb(
17871787
array_value {
17881788
values { int_value: 1 }
17891789
values { int_value: 2 }
@@ -1793,10 +1793,10 @@ TEST(Value, TypeAndValuesMatchArray) {
17931793
}
17941794

17951795
TEST(Value, TypeAndValuesMatchArrayMismatchElementType) {
1796-
auto type = R"pb(
1796+
auto const* type = R"pb(
17971797
array_type { element_type { int64_type {} } }
17981798
)pb";
1799-
auto mismatched_value = R"pb(
1799+
auto const* mismatched_value = R"pb(
18001800
array_value {
18011801
values { int_value: 1 }
18021802
values { string_value: "2" }
@@ -1806,17 +1806,17 @@ TEST(Value, TypeAndValuesMatchArrayMismatchElementType) {
18061806
}
18071807

18081808
TEST(Value, TypeAndValuesMatchArrayMismatchScalar) {
1809-
auto type = R"pb(
1809+
auto const* type = R"pb(
18101810
array_type { element_type { int64_type {} } }
18111811
)pb";
18121812
TestTypeAndValuesMatch(type, "int_value: 123", false);
18131813
}
18141814

18151815
TEST(Value, TypeAndValuesMatchArrayWithNull) {
1816-
auto type = R"pb(
1816+
auto const* type = R"pb(
18171817
array_type { element_type { int64_type {} } }
18181818
)pb";
1819-
auto value_with_null = R"pb(
1819+
auto const* value_with_null = R"pb(
18201820
array_value {
18211821
values { int_value: 1 }
18221822
values {} # null
@@ -1827,7 +1827,7 @@ TEST(Value, TypeAndValuesMatchArrayWithNull) {
18271827
}
18281828

18291829
TEST(Value, TypeAndValuesMatchStruct) {
1830-
auto type = R"pb(
1830+
auto const* type = R"pb(
18311831
struct_type {
18321832
fields {
18331833
field_name: "name"
@@ -1839,7 +1839,7 @@ TEST(Value, TypeAndValuesMatchStruct) {
18391839
}
18401840
}
18411841
)pb";
1842-
auto matching_value = R"pb(
1842+
auto const* matching_value = R"pb(
18431843
array_value {
18441844
values { string_value: "John" }
18451845
values { int_value: 42 }
@@ -1849,7 +1849,7 @@ TEST(Value, TypeAndValuesMatchStruct) {
18491849
}
18501850

18511851
TEST(Value, TypeAndValuesMatchStructMismatchFieldType) {
1852-
auto type = R"pb(
1852+
auto const* type = R"pb(
18531853
struct_type {
18541854
fields {
18551855
field_name: "name"
@@ -1861,7 +1861,7 @@ TEST(Value, TypeAndValuesMatchStructMismatchFieldType) {
18611861
}
18621862
}
18631863
)pb";
1864-
auto mismatched_value = R"pb(
1864+
auto const* mismatched_value = R"pb(
18651865
array_value {
18661866
values { string_value: "John" }
18671867
values { string_value: "42" }
@@ -1871,13 +1871,13 @@ TEST(Value, TypeAndValuesMatchStructMismatchFieldType) {
18711871
}
18721872

18731873
TEST(Value, TypeAndValuesMatchStructMismatchFieldCount) {
1874-
auto type = R"pb(
1874+
auto const* type = R"pb(
18751875
struct_type {
18761876
fields { type { string_type {} } }
18771877
fields { type { int64_type {} } }
18781878
}
18791879
)pb";
1880-
auto mismatched_value = R"pb(
1880+
auto const* mismatched_value = R"pb(
18811881
array_value { values { string_value: "John" } }
18821882
)pb";
18831883
// The current implementation has a bug and will return true here.
@@ -1886,20 +1886,20 @@ TEST(Value, TypeAndValuesMatchStructMismatchFieldCount) {
18861886
}
18871887

18881888
TEST(Value, TypeAndValuesMatchStructMismatchScalar) {
1889-
auto type = R"pb(
1889+
auto const* type = R"pb(
18901890
struct_type { fields { type { string_type {} } } }
18911891
)pb";
18921892
TestTypeAndValuesMatch(type, "string_value: 'John'", false);
18931893
}
18941894

18951895
TEST(Value, TypeAndValuesMatchStructWithNull) {
1896-
auto type = R"pb(
1896+
auto const* type = R"pb(
18971897
struct_type {
18981898
fields { type { string_type {} } }
18991899
fields { type { int64_type {} } }
19001900
}
19011901
)pb";
1902-
auto value_with_null = R"pb(
1902+
auto const* value_with_null = R"pb(
19031903
array_value {
19041904
values { string_value: "John" }
19051905
values {}
@@ -1909,13 +1909,13 @@ TEST(Value, TypeAndValuesMatchStructWithNull) {
19091909
}
19101910

19111911
TEST(Value, TypeAndValuesMatchMap) {
1912-
auto type = R"pb(
1912+
auto const* type = R"pb(
19131913
map_type {
19141914
key_type { string_type {} }
19151915
value_type { int64_type {} }
19161916
}
19171917
)pb";
1918-
auto matching_value = R"pb(
1918+
auto const* matching_value = R"pb(
19191919
array_value {
19201920
values {
19211921
array_value {
@@ -1929,13 +1929,13 @@ TEST(Value, TypeAndValuesMatchMap) {
19291929
}
19301930

19311931
TEST(Value, TypeAndValuesMatchMapMismatchKeyType) {
1932-
auto type = R"pb(
1932+
auto const* type = R"pb(
19331933
map_type {
19341934
key_type { string_type {} }
19351935
value_type { int64_type {} }
19361936
}
19371937
)pb";
1938-
auto mismatched_value = R"pb(
1938+
auto const* mismatched_value = R"pb(
19391939
array_value {
19401940
values {
19411941
array_value {
@@ -1949,13 +1949,13 @@ TEST(Value, TypeAndValuesMatchMapMismatchKeyType) {
19491949
}
19501950

19511951
TEST(Value, TypeAndValuesMatchMapMismatchValueType) {
1952-
auto type = R"pb(
1952+
auto const* type = R"pb(
19531953
map_type {
19541954
key_type { string_type {} }
19551955
value_type { int64_type {} }
19561956
}
19571957
)pb";
1958-
auto mismatched_value = R"pb(
1958+
auto const* mismatched_value = R"pb(
19591959
array_value {
19601960
values {
19611961
array_value {
@@ -1969,7 +1969,7 @@ TEST(Value, TypeAndValuesMatchMapMismatchValueType) {
19691969
}
19701970

19711971
TEST(Value, TypeAndValuesMatchMapMismatchScalar) {
1972-
auto type = R"pb(
1972+
auto const* type = R"pb(
19731973
map_type {
19741974
key_type { string_type {} }
19751975
value_type { int64_type {} }
@@ -1979,26 +1979,26 @@ TEST(Value, TypeAndValuesMatchMapMismatchScalar) {
19791979
}
19801980

19811981
TEST(Value, TypeAndValuesMatchMapMalformedEntry) {
1982-
auto type = R"pb(
1982+
auto const* type = R"pb(
19831983
map_type {
19841984
key_type { string_type {} }
19851985
value_type { int64_type {} }
19861986
}
19871987
)pb";
1988-
auto malformed_value = R"pb(
1988+
auto const* malformed_value = R"pb(
19891989
array_value { values { array_value { values { string_value: "key1" } } } }
19901990
)pb";
19911991
TestTypeAndValuesMatch(type, malformed_value, false);
19921992
}
19931993

19941994
TEST(Value, TypeAndValuesMatchMapWithNullValue) {
1995-
auto type = R"pb(
1995+
auto const* type = R"pb(
19961996
map_type {
19971997
key_type { string_type {} }
19981998
value_type { int64_type {} }
19991999
}
20002000
)pb";
2001-
auto value_with_null = R"pb(
2001+
auto const* value_with_null = R"pb(
20022002
array_value {
20032003
values {
20042004
array_value {

0 commit comments

Comments
 (0)