  
    // TODO: should we build a new layout and swap it in?
    clearLayout(destinations_layout);
  
    // Sort: HOME, WORK, alphabetical FAVORITES, and then most recent (as returned by API)
    std::stable_sort(destinations.begin(), destinations.end(), [](const auto &a, const auto &b) {
      if (a->isFavorite() && b->isFavorite()) {
        if (a->label() == NAV_FAVORITE_LABEL_HOME) return true;
        else if (b->label() == NAV_FAVORITE_LABEL_HOME) return false;
        else if (a->label() == NAV_FAVORITE_LABEL_WORK) return true;
        else if (b->label() == NAV_FAVORITE_LABEL_WORK) return false;
        else return a->name() < b->name();
      }
      else if (a->isFavorite()) return true;
      else if (b->isFavorite()) return false;
      return false;
    });
 
</s> remove     else if (a->isFavorite()) return true;
    else if (b->isFavorite()) return false;
    return false;
  });
 </s> add     if (dest == current_destination) continue; </s> remove   bool has_home = false, has_work = false;
  auto destinations = std::vector<std::unique_ptr<NavDestination>>();

  auto destinations_str = cur_destinations.trimmed();
  if (!destinations_str.isEmpty()) {
    QJsonDocument doc = QJsonDocument::fromJson(destinations_str.toUtf8());
    if (doc.isNull()) {
      qWarning() << "JSON Parse failed on navigation locations" << cur_destinations;
      return;
    }

    for (auto el : doc.array()) {
      auto destination = std::make_unique<NavDestination>(el.toObject());

      // add home and work later if they are missing
      if (destination->isFavorite()) {
        if (destination->label() == NAV_FAVORITE_LABEL_HOME) has_home = true;
        else if (destination->label() == NAV_FAVORITE_LABEL_WORK) has_work = true;
      }

      // skip current destination
      if (current_destination && *destination == *current_destination) continue;
      destinations.push_back(std::move(destination));
    }
  }

 </s> add   setUpdatesEnabled(false); </s> remove   for (auto &destination : destinations) {
 </s> add  </s> remove class NavDestination {
public:
  explicit NavDestination(const QJsonObject &place)
      : type_(place["save_type"].toString()), label_(place["label"].toString()),
        name_(place["place_name"].toString()), details_(place["place_details"].toString()),
        latitude_(place["latitude"].toDouble()), longitude_(place["longitude"].toDouble()) {
    // if details starts with `name, ` remove it
    if (details_.startsWith(name_ + ", ")) {
      details_ = details_.mid(name_.length() + 2);
    }
  }

  QString type() const { return type_; }
  QString label() const { return label_; }
  QString name() const { return name_; }
  QString details() const { return details_; }

  bool isFavorite() const { return type_ == NAV_TYPE_FAVORITE; }
  bool isRecent() const { return type_ == NAV_TYPE_RECENT; }

  bool operator==(const NavDestination &rhs) {
    return type_ == rhs.type_ && label_ == rhs.label_ && name_ == rhs.name_ &&
           details_ == rhs.details_ && latitude_ == rhs.latitude_ && longitude_ == rhs.longitude_;
  }

  QJsonObject toJson() const {
    QJsonObject obj;
    obj["save_type"] = type_;
    obj["label"] = label_;
    obj["place_name"] = name_;
    obj["place_details"] = details_;
    obj["latitude"] = latitude_;
    obj["longitude"] = longitude_;
    return obj;
  }

private:
  QString type_, label_, name_, details_;
  double latitude_, longitude_;
};

 </s> add  </s> remove   if (destination->isFavorite()) {
    if (destination->label() == NAV_FAVORITE_LABEL_HOME) {
 </s> add   if (destination["save_type"] == NAV_TYPE_FAVORITE) {
    if (destination["label"] == NAV_FAVORITE_LABEL_HOME) {
  bool has_home = false, has_work = false;
  for (auto location : current_locations) {
    auto dest = location.toObject();
    if (dest["save_type"].toString() == NAV_TYPE_FAVORITE) {
      has_home = has_home || dest["label"].toString() == NAV_FAVORITE_LABEL_HOME;
      has_work = has_work || dest["label"].toString() == NAV_FAVORITE_LABEL_WORK;
  
    // TODO: should we build a new layout and swap it in?
    clearLayout(destinations_layout);
  
  bool has_home = false, has_work = false;
  for (auto location : current_locations) {
    auto dest = location.toObject();
    if (dest["save_type"].toString() == NAV_TYPE_FAVORITE) {
      has_home = has_home || dest["label"].toString() == NAV_FAVORITE_LABEL_HOME;
      has_work = has_work || dest["label"].toString() == NAV_FAVORITE_LABEL_WORK;
  bool has_home = false, has_work = false;
  for (auto location : current_locations) {
    auto dest = location.toObject();
    if (dest["save_type"].toString() == NAV_TYPE_FAVORITE) {
      has_home = has_home || dest["label"].toString() == NAV_FAVORITE_LABEL_HOME;
      has_work = has_work || dest["label"].toString() == NAV_FAVORITE_LABEL_WORK;
  bool has_home = false, has_work = false;
  for (auto location : current_locations) {
    auto dest = location.toObject();
    if (dest["save_type"].toString() == NAV_TYPE_FAVORITE) {
      has_home = has_home || dest["label"].toString() == NAV_FAVORITE_LABEL_HOME;
      has_work = has_work || dest["label"].toString() == NAV_FAVORITE_LABEL_WORK;
  bool has_home = false, has_work = false;
  for (auto location : current_locations) {
    auto dest = location.toObject();
    if (dest["save_type"].toString() == NAV_TYPE_FAVORITE) {
      has_home = has_home || dest["label"].toString() == NAV_FAVORITE_LABEL_HOME;
      has_work = has_work || dest["label"].toString() == NAV_FAVORITE_LABEL_WORK;
  bool has_home = false, has_work = false;
  for (auto location : current_locations) {
    auto dest = location.toObject();
    if (dest["save_type"].toString() == NAV_TYPE_FAVORITE) {
      has_home = has_home || dest["label"].toString() == NAV_FAVORITE_LABEL_HOME;
      has_work = has_work || dest["label"].toString() == NAV_FAVORITE_LABEL_WORK;
  bool has_home = false, has_work = false;
  for (auto location : current_locations) {
    auto dest = location.toObject();
    if (dest["save_type"].toString() == NAV_TYPE_FAVORITE) {
      has_home = has_home || dest["label"].toString() == NAV_FAVORITE_LABEL_HOME;
      has_work = has_work || dest["label"].toString() == NAV_FAVORITE_LABEL_WORK;
  bool has_home = false, has_work = false;
  for (auto location : current_locations) {
    auto dest = location.toObject();
    if (dest["save_type"].toString() == NAV_TYPE_FAVORITE) {
      has_home = has_home || dest["label"].toString() == NAV_FAVORITE_LABEL_HOME;
      has_work = has_work || dest["label"].toString() == NAV_FAVORITE_LABEL_WORK;
  bool has_home = false, has_work = false;
  for (auto location : current_locations) {
    auto dest = location.toObject();
    if (dest["save_type"].toString() == NAV_TYPE_FAVORITE) {
      has_home = has_home || dest["label"].toString() == NAV_FAVORITE_LABEL_HOME;
      has_work = has_work || dest["label"].toString() == NAV_FAVORITE_LABEL_WORK;
      }
      else if (a->isFavorite()) return true;
      else if (b->isFavorite()) return false;
      return false;
    });
keep keep keep keep replace replace replace replace replace replace replace replace keep keep keep keep keep
 ui/MapSettings: sort location JsonArray inplace (#28886) 
selfdrive/ui/qt/maps/map_settings.cc