|
30 | 30 | #include "absl/strings/str_cat.h"
|
31 | 31 | #include "absl/strings/str_replace.h"
|
32 | 32 | #include "absl/strings/string_view.h"
|
| 33 | +#include "absl/strings/strip.h" |
33 | 34 | #include "google/protobuf/descriptor.pb.h"
|
34 | 35 | #include "google/protobuf/io/coded_stream.h"
|
35 | 36 | #include "google/protobuf/parse_context.h"
|
@@ -492,6 +493,18 @@ class EncodedDescriptorDatabase::DescriptorIndex {
|
492 | 493 | auto p = package(index);
|
493 | 494 | return absl::StrCat(p, p.empty() ? "" : ".", symbol(index));
|
494 | 495 | }
|
| 496 | + |
| 497 | + bool IsSubSymbolOf(const DescriptorIndex& index, |
| 498 | + absl::string_view super_symbol) const { |
| 499 | + const auto consume_part = [&](absl::string_view part) { |
| 500 | + if (!absl::ConsumePrefix(&super_symbol, part)) return false; |
| 501 | + return super_symbol.empty() || absl::ConsumePrefix(&super_symbol, "."); |
| 502 | + }; |
| 503 | + if (auto p = package(index); !p.empty()) { |
| 504 | + if (!consume_part(p)) return false; |
| 505 | + } |
| 506 | + return consume_part(symbol(index)); |
| 507 | + } |
495 | 508 | };
|
496 | 509 |
|
497 | 510 | struct SymbolCompare {
|
@@ -793,8 +806,7 @@ EncodedDescriptorDatabase::DescriptorIndex::FindSymbolOnlyFlat(
|
793 | 806 | auto iter =
|
794 | 807 | FindLastLessOrEqual(&by_symbol_flat_, name, by_symbol_.key_comp());
|
795 | 808 |
|
796 |
| - return iter != by_symbol_flat_.end() && |
797 |
| - IsSubSymbol(iter->AsString(*this), name) |
| 809 | + return iter != by_symbol_flat_.end() && iter->IsSubSymbolOf(*this, name) |
798 | 810 | ? all_values_[iter->data_offset].value()
|
799 | 811 | : Value();
|
800 | 812 | }
|
|
0 commit comments