summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog8
-rw-r--r--freedesktop.org.xml.in1
-rw-r--r--shared-mime-info-spec.xml10
-rw-r--r--update-mime-database.c95
4 files changed, 62 insertions, 52 deletions
diff --git a/ChangeLog b/ChangeLog
index a1dba683..eecf1775 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2008-06-09 Bastien Nocera <hadess@hadess.net>
+
+ * freedesktop.org.xml.in: Add weight to the DTD (patch by Matthias)
+ * shared-mime-info-spec.xml:
+ * update-mime-database.c (insert_suffix), (write_suffix_entries),
+ (write_suffix_cache): Patch by Matthias Clasen
+ <mclasen@redhat.com> to implement the compact suffix tree
+
2008-06-02 Bastien Nocera <hadess@hadess.net>
* freedesktop.org.xml.in: Fix pack200 magic, remove useless gtkrc
diff --git a/freedesktop.org.xml.in b/freedesktop.org.xml.in
index 9a1cc7f1..b9092844 100644
--- a/freedesktop.org.xml.in
+++ b/freedesktop.org.xml.in
@@ -25,6 +25,7 @@
<!ELEMENT glob EMPTY>
<!ATTLIST glob pattern CDATA #REQUIRED>
+ <!ATTLIST glob weight CDATA #IMPLIED>
<!ELEMENT magic (match)+>
<!ATTLIST magic priority CDATA #IMPLIED>
diff --git a/shared-mime-info-spec.xml b/shared-mime-info-spec.xml
index 8899000e..d020f1b3 100644
--- a/shared-mime-info-spec.xml
+++ b/shared-mime-info-spec.xml
@@ -639,9 +639,12 @@ ReverseSuffixTree:
ReverseSuffixTreeNode:
4 CARD32 CHARACTER
-4 CARD32 MIME_TYPE_OFFSET
4 CARD32 N_CHILDREN
4 CARD32 FIRST_CHILD_OFFSET
+
+ReverseSuffixTreeLeafNode:
+4 CARD32 0
+4 CARD32 MIME_TYPE_OFFSET
4 CARD32 WEIGHT
MagicList:
@@ -691,8 +694,9 @@ The list of namespaces is sorted by namespace uri. The list of icons
is sorted by mimetype.
</para>
<para>
-Identical globs are stored in the suffix tree by appending suffix
-tree nodes with '\0' as character.
+Mimetypes are stored in the suffix tree by appending suffix
+tree leaf nodes with '\0' as character. These nodes appear at the
+beginning of the list of children.
</para>
<para>
All offsets are in bytes from the beginning of the file.
diff --git a/update-mime-database.c b/update-mime-database.c
index 67c67a31..fc99be41 100644
--- a/update-mime-database.c
+++ b/update-mime-database.c
@@ -2127,45 +2127,33 @@ insert_suffix (gunichar *suffix,
if (suffix[1] == 0)
{
- if (s->mimetype != NULL)
+ GList *l2;
+ SuffixEntry *s2;
+ gboolean found = FALSE;
+
+ for (l2 = s->children; l2; l2 = l2->next)
{
- if (strcmp (s->mimetype, mimetype) != 0)
+ s2 = (SuffixEntry *)l2->data;
+ if (s2->character != 0)
+ break;
+ if (strcmp (s2->mimetype, mimetype) == 0)
{
- GList *l2;
- SuffixEntry *s2;
- gboolean found = FALSE;
-
- for (l2 = s->children; l2; l2 = l2->next)
- {
- s2 = (SuffixEntry *)l2->data;
- if (s2->character != '\0')
- break;
- if (strcmp (s2->mimetype, mimetype) == 0)
- {
- if (s2->weight < weight)
- s2->weight = weight;
- found = TRUE;
- break;
- }
- }
- if (!found)
- {
- s2 = g_new0 (SuffixEntry, 1);
- s2->character = '\0';
- s2->mimetype = mimetype;
- s2->weight = weight;
- s2->children = NULL;
-
- s->children = g_list_prepend (s->children, s2);
- }
+ if (s2->weight < weight)
+ s2->weight = weight;
+ found = TRUE;
+ break;
}
}
- else
- {
- s->mimetype = mimetype;
- s->weight = weight;
- }
- }
+ if (!found)
+ {
+ s2 = g_new0 (SuffixEntry, 1);
+ s2->character = 0;
+ s2->mimetype = mimetype;
+ s2->weight = weight;
+ s2->children = NULL;
+ s->children = g_list_insert_before (s->children, l2, s2);
+ }
+ }
else
s->children = insert_suffix (suffix + 1, mimetype, weight, s->children);
@@ -2265,8 +2253,6 @@ write_suffix_entries (FILE *cache,
return !error;
}
- write_card32 (cache, entry->character);
-
if (entry->mimetype)
{
offset = GPOINTER_TO_UINT(g_hash_table_lookup (strings, entry->mimetype));
@@ -2279,19 +2265,30 @@ write_suffix_entries (FILE *cache,
else
offset = 0;
- if (!write_card32 (cache, offset))
- return FALSE;
-
- if (!write_card32 (cache, g_list_length (entry->children)))
- return FALSE;
-
- if (!write_card32 (cache, *child_offset))
- return FALSE;
+ if (entry->character == 0)
+ {
+ if (!write_card32 (cache, entry->character))
+ return FALSE;
- if (!write_card32 (cache, entry->weight))
- return FALSE;
+ if (!write_card32 (cache, offset))
+ return FALSE;
+
+ if (!write_card32 (cache, entry->weight))
+ return FALSE;
+ }
+ else
+ {
+ if (!write_card32 (cache, entry->character))
+ return FALSE;
+
+ if (!write_card32 (cache, g_list_length (entry->children)))
+ return FALSE;
+
+ if (!write_card32 (cache, *child_offset))
+ return FALSE;
+ }
- *child_offset += 20 * g_list_length (entry->children);
+ *child_offset += 12 * g_list_length (entry->children);
return TRUE;
}
@@ -2313,7 +2310,7 @@ write_suffix_cache (FILE *cache,
n_entries = g_list_length (suffixes);
*offset += 8;
- child_offset = *offset + 20 * n_entries;
+ child_offset = *offset + 12 * n_entries;
depth = 0;
for (s = suffixes; s; s= s->next)
{