| 1494 | } |
| 1495 | |
| 1496 | bool TypeEquals(const DataType& left, const DataType& right, bool check_metadata) { |
| 1497 | // The arrays are the same object |
| 1498 | if (&left == &right) { |
| 1499 | return true; |
| 1500 | } else if (left.id() != right.id()) { |
| 1501 | return false; |
| 1502 | } else { |
| 1503 | // First try to compute fingerprints |
| 1504 | if (check_metadata) { |
| 1505 | const auto& left_metadata_fp = left.metadata_fingerprint(); |
| 1506 | const auto& right_metadata_fp = right.metadata_fingerprint(); |
| 1507 | if (left_metadata_fp != right_metadata_fp) { |
| 1508 | return false; |
| 1509 | } |
| 1510 | } |
| 1511 | |
| 1512 | const auto& left_fp = left.fingerprint(); |
| 1513 | const auto& right_fp = right.fingerprint(); |
| 1514 | if (!left_fp.empty() && !right_fp.empty()) { |
| 1515 | return left_fp == right_fp; |
| 1516 | } |
| 1517 | |
| 1518 | // TODO remove check_metadata here? |
| 1519 | TypeEqualsVisitor visitor(right, check_metadata); |
| 1520 | auto error = VisitTypeInline(left, &visitor); |
| 1521 | if (!error.ok()) { |
| 1522 | DCHECK(false) << "Types are not comparable: " << error.ToString(); |
| 1523 | } |
| 1524 | return visitor.result(); |
| 1525 | } |
| 1526 | } |
| 1527 | |
| 1528 | namespace { |
| 1529 | |