MCPcopy Create free account
hub / github.com/apache/trafficserver / find_or_create_node

Method find_or_create_node

src/traffic_ctl/FileConfigCommand.cc:153–176  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

151} // namespace
152
153YAML::Node
154FlatYAMLAccessor::find_or_create_node(swoc::TextView variable, bool search_all)
155{
156 if (!search_all) {
157 if (_docs.size() == 0) {
158 // If nothing in it. Add one, it'll be the new node.
159 _docs.emplace_back(YAML::NodeType::Map);
160 }
161 } else {
162 for (auto iter = _docs.rbegin(); iter != _docs.rend(); ++iter) {
163 if (auto [found, node] = search_node(variable, *iter, DO_NOT_CREATE_IF_NOT_EXIST); found) {
164 return node;
165 }
166 }
167 // We haven't found the node, so we will create a new field in the latest doc.
168 if (_docs.size() == 0) {
169 // if nothing in it. Add one, it'll be the new node.
170 _docs.emplace_back(YAML::NodeType::Map);
171 }
172 // Use the last doc.
173 }
174
175 return search_node(variable, _docs.back(), CREATE_IF_NOT_EXIST).second;
176}
177
178std::pair<bool, YAML::Node>
179FlatYAMLAccessor::find_node(swoc::TextView variable)

Callers

nothing calls this directly

Calls 3

search_nodeFunction · 0.85
emplace_backMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected