| 2175 | } |
| 2176 | |
| 2177 | struct Matches { |
| 2178 | // referents[i] is referenced by prefixes[i] |
| 2179 | std::vector<FieldPath> prefixes; |
| 2180 | FieldVector referents; |
| 2181 | |
| 2182 | Matches(std::vector<FieldPath> matches, const FieldVector& fields) { |
| 2183 | for (auto& match : matches) { |
| 2184 | Add({}, std::move(match), fields); |
| 2185 | } |
| 2186 | } |
| 2187 | |
| 2188 | Matches() = default; |
| 2189 | |
| 2190 | size_t size() const { return referents.size(); } |
| 2191 | |
| 2192 | void Add(const FieldPath& prefix, const FieldPath& suffix, |
| 2193 | const FieldVector& fields) { |
| 2194 | auto maybe_field = suffix.Get(fields); |
| 2195 | DCHECK_OK(maybe_field); |
| 2196 | referents.push_back(std::move(maybe_field).ValueOrDie()); |
| 2197 | |
| 2198 | std::vector<int> concatenated_indices(prefix.indices().size() + |
| 2199 | suffix.indices().size()); |
| 2200 | auto it = concatenated_indices.begin(); |
| 2201 | for (auto path : {&prefix, &suffix}) { |
| 2202 | it = std::copy(path->indices().begin(), path->indices().end(), it); |
| 2203 | } |
| 2204 | prefixes.emplace_back(std::move(concatenated_indices)); |
| 2205 | } |
| 2206 | }; |
| 2207 | |
| 2208 | std::vector<FieldPath> operator()(const std::vector<FieldRef>& refs) { |
| 2209 | DCHECK_GE(refs.size(), 1); |