ovsdb-data: Short-circuit ovsdb_datum_includes_all() in trivial case.
[sliver-openvswitch.git] / lib / ovsdb-data.c
index 150ae61..bb8781c 100644 (file)
@@ -690,8 +690,7 @@ check_string_constraints(const char *s,
         struct ovsdb_error *error;
 
         error = ovsdb_error("constraint violation",
-                            "\"%s\" is not a valid UTF-8 string: %s",
-                            s, msg);
+                            "not a valid UTF-8 string: %s", msg);
         free(msg);
         return error;
     }
@@ -1279,30 +1278,30 @@ struct json *
 ovsdb_datum_to_json(const struct ovsdb_datum *datum,
                     const struct ovsdb_type *type)
 {
-    if (datum->n == 1 && !ovsdb_type_is_map(type)) {
-        return ovsdb_atom_to_json(&datum->keys[0], type->key.type);
-    } else if (type->value.type == OVSDB_TYPE_VOID) {
+    if (ovsdb_type_is_map(type)) {
         struct json **elems;
         size_t i;
 
         elems = xmalloc(datum->n * sizeof *elems);
         for (i = 0; i < datum->n; i++) {
-            elems[i] = ovsdb_atom_to_json(&datum->keys[i], type->key.type);
+            elems[i] = json_array_create_2(
+                ovsdb_atom_to_json(&datum->keys[i], type->key.type),
+                ovsdb_atom_to_json(&datum->values[i], type->value.type));
         }
 
-        return wrap_json("set", json_array_create(elems, datum->n));
+        return wrap_json("map", json_array_create(elems, datum->n));
+    } else if (datum->n == 1) {
+        return ovsdb_atom_to_json(&datum->keys[0], type->key.type);
     } else {
         struct json **elems;
         size_t i;
 
         elems = xmalloc(datum->n * sizeof *elems);
         for (i = 0; i < datum->n; i++) {
-            elems[i] = json_array_create_2(
-                ovsdb_atom_to_json(&datum->keys[i], type->key.type),
-                ovsdb_atom_to_json(&datum->values[i], type->value.type));
+            elems[i] = ovsdb_atom_to_json(&datum->keys[i], type->key.type);
         }
 
-        return wrap_json("map", json_array_create(elems, datum->n));
+        return wrap_json("set", json_array_create(elems, datum->n));
     }
 }
 
@@ -1688,6 +1687,9 @@ ovsdb_datum_includes_all(const struct ovsdb_datum *a,
 {
     size_t i;
 
+    if (a->n > b->n) {
+        return false;
+    }
     for (i = 0; i < a->n; i++) {
         if (ovsdb_datum_find(a, i, b, type) == UINT_MAX) {
             return false;