Enable ATTR_INTLIST to contain zeros. Use the same encoding as IDARRAY.
authorMichael Matz <matz@suse.de>
Thu, 27 Dec 2007 21:39:00 +0000 (21:39 +0000)
committerMichael Matz <matz@suse.de>
Thu, 27 Dec 2007 21:39:00 +0000 (21:39 +0000)
src/attr_store.c
src/attr_store_p.h
src/repo_solv.c
tools/dumpattr.c
tools/dumpsolv.c

index a96523c..1870532 100644 (file)
@@ -369,24 +369,19 @@ void
 add_attr_intlist_int (Attrstore *s, unsigned int entry, Id name, int val)
 {
   LongNV *nv = find_attr (s, entry, name);
-  if (val == 0)
-    return;
   if (nv)
     {
-      unsigned len = 0;
-      while (nv->v.intlist[len])
-        len++;
+      unsigned len = nv->v.intlist[0]++;
       nv->v.intlist = realloc (nv->v.intlist, (len + 2) * sizeof (nv->v.intlist[0]));
-      nv->v.intlist[len] = val;
-      nv->v.intlist[len+1] = 0;
+      nv->v.intlist[len+1] = val;
     }
   else
     {
       LongNV mynv;
       mynv.key = add_key (s, name, TYPE_ATTR_INTLIST, 0);
       mynv.v.intlist = malloc (2 * sizeof (mynv.v.intlist[0]));
-      mynv.v.intlist[0] = val;
-      mynv.v.intlist[1] = 0;
+      mynv.v.intlist[0] = 1;
+      mynv.v.intlist[1] = val;
       add_attr (s, entry, mynv);
     }
 }
@@ -437,9 +432,9 @@ merge_attrs (Attrstore *s, unsigned dest, unsigned src)
            {
              case TYPE_ATTR_INTLIST:
                {
-                 unsigned len = 0;
-                 while (nv->v.intlist[len])
-                   add_attr_intlist_int (s, dest, s->keys[nv->key].name, nv->v.intlist[len++]);
+                 unsigned i, len = nv->v.intlist[0];
+                 for (i = 0; i < len; i++)
+                   add_attr_intlist_int (s, dest, s->keys[nv->key].name, nv->v.intlist[i + 1]);
                }
                break;
              case TYPE_ATTR_LOCALIDS:
@@ -523,10 +518,11 @@ add_attr_from_file (Attrstore *s, unsigned entry, Id name, int type, Id *idmap,
        }
        break;
       case TYPE_ATTR_INTLIST:
-        {
-         unsigned i;
-         while ((i = read_id(fp, 0)) != 0)
-           add_attr_intlist_int (s, entry, name, i);
+       {
+         int i;
+         while ((i = read_id(fp, 0)) & 64)
+           add_attr_intlist_int (s, entry, name, (i & 63) | ((i >> 1) & ~63));
+         add_attr_intlist_int (s, entry, name, (i & 63) | ((i >> 1) & ~63));
        }
        break;
       case TYPE_ATTR_LOCALIDS:
@@ -881,11 +877,18 @@ attr_store_pack (Attrstore *s)
            case TYPE_ATTR_INTLIST:
              {
                const int *il = nv[ofs].v.intlist;
-               int i;
-               for (; (i = *il) != 0; il++, old_mem += 4)
-                 add_num (s->flat_attrs, s->attr_next_free, i, FLAT_ATTR_BLOCK);
-               add_num (s->flat_attrs, s->attr_next_free, 0, FLAT_ATTR_BLOCK);
-               old_mem+=4;
+               int len = *il++;
+               //add_num (s->flat_attrs, s->attr_next_free, len, FLAT_ATTR_BLOCK);
+               old_mem += 4 * (len + 1);
+               while (len--)
+                 {
+                   int i = *il++;
+                   if (i >= 64)
+                     i = (i & 63) | ((i & ~63) << 1);
+                   if (len)
+                     i |= 64;
+                   add_num (s->flat_attrs, s->attr_next_free, i, FLAT_ATTR_BLOCK);
+                 }
                xfree (nv[ofs].v.intlist);
                break;
              }
@@ -974,9 +977,9 @@ attr_store_unpack (Attrstore *s)
                  {
                    int val;
                    get_num (ai.as_numlist, val);
-                   if (!val)
+                   add_attr_intlist_int (s, i, ai.name, (val & 63) | ((val >> 1) & ~63));
+                   if (!(val & 64))
                      break;
-                   add_attr_intlist_int (s, i, ai.name, val);
                  }
                break;
              }
index e840333..981d383 100644 (file)
@@ -179,12 +179,12 @@ ai_step (Attrstore *s, attr_iterator *ai)
       }
     case TYPE_ATTR_INTLIST:
       {
-        ai->as_numlist = ai->attrs_next;
+       ai->as_numlist = ai->attrs_next;
        while (1)
          {
            int val;
            get_num (ai->attrs_next, val);
-           if (!val)
+           if (!(val & 64))
              break;
          }
        break;
index e494c0a..0371320 100644 (file)
@@ -269,6 +269,7 @@ skip_item (Repodata *data, unsigned type, unsigned numid, unsigned numrel)
       case TYPE_IDVALUEARRAY:
       case TYPE_IDVALUEVALUEARRAY:
       case TYPE_REL_IDARRAY:
+      case TYPE_ATTR_INTLIST:
        while ((read_u8(data) & 0xc0) != 0)
          ;
        break;
@@ -297,7 +298,6 @@ skip_item (Repodata *data, unsigned type, unsigned numid, unsigned numrel)
       case TYPE_ATTR_INT:
        read_id(data, 0);
        break;
-      case TYPE_ATTR_INTLIST:
       case TYPE_ATTR_LOCALIDS:
        while (read_id(data, 0) != 0)
          ;
index 5930f1c..3fb8d4f 100644 (file)
@@ -49,9 +49,9 @@ dump_attrs (Attrstore *s, unsigned int entry)
              {
                int val;
                get_num (ai.as_numlist, val);
-               if (!val)
+               fprintf (stdout, " %d", (val & 63) | ((val >> 1) & ~63));
+               if (!(val & 64))
                  break;
-               fprintf (stdout, " %d", val);
              }
            fprintf (stdout, "\n");
            break;
index f130227..06083d9 100644 (file)
@@ -46,9 +46,9 @@ dump_attrs_1 (Attrstore *s, unsigned int entry)
              {
                int val;
                get_num (ai.as_numlist, val);
-               if (!val)
+               fprintf (stdout, " %d", (val & 63) | ((val >> 1) & ~63));
+               if (!(val & 64))
                  break;
-               fprintf (stdout, " %d", val);
              }
            fprintf (stdout, "\n");
            break;