| 53 | AttrSlice::AttrSlice(const AttrValueMap* a) : ndef_(nullptr), attrs_(a) {} |
| 54 | |
| 55 | string SummarizeAttrsHelper(AttrSlice attrs, StringPiece device) { |
| 56 | string ret; |
| 57 | |
| 58 | // We sort the attrs so the output is deterministic. |
| 59 | std::vector<string> attr_names; |
| 60 | attr_names.reserve(attrs.size()); |
| 61 | for (const auto& attr : attrs) { |
| 62 | attr_names.push_back(attr.first); |
| 63 | } |
| 64 | std::sort(attr_names.begin(), attr_names.end()); |
| 65 | bool first = true; |
| 66 | for (const string& attr_name : attr_names) { |
| 67 | if (!first) strings::StrAppend(&ret, ", "); |
| 68 | first = false; |
| 69 | strings::StrAppend(&ret, attr_name, "=", |
| 70 | SummarizeAttrValue(*attrs.Find(attr_name))); |
| 71 | } |
| 72 | |
| 73 | // Consider the device to be a final attr with name "_device". |
| 74 | if (!device.empty()) { |
| 75 | if (!first) strings::StrAppend(&ret, ", "); |
| 76 | first = false; |
| 77 | strings::StrAppend(&ret, "_device=\"", device, "\""); |
| 78 | } |
| 79 | return ret; |
| 80 | } |
| 81 | |
| 82 | string AttrSlice::SummarizeNode() const { |
| 83 | return ndef_ ? SummarizeNodeDef(*ndef_) |
no test coverage detected