[dovecot-cvs] dovecot/src/plugins/fts-squat squat-trie-private.h, NONE, 1.1 squat-trie.c, 1.13, 1.14

tss at dovecot.org tss at dovecot.org
Wed Jan 24 14:41:31 UTC 2007


Update of /var/lib/cvs/dovecot/src/plugins/fts-squat
In directory talvi:/tmp/cvs-serv11445

Modified Files:
	squat-trie.c 
Added Files:
	squat-trie-private.h 
Log Message:
Some bugfixes. Moved header struct to a separate file.



--- NEW FILE: squat-trie-private.h ---
#ifndef __SQUAT_TRIE_PRIVATE_H
#define __SQUAT_TRIE_PRIVATE_H

struct squat_trie_header {
	uint8_t version;
	uint8_t unused[3];

	uint32_t uidvalidity;
	uint32_t used_file_size;
	uint32_t deleted_space;
	uint32_t node_count;
	uint32_t modify_counter;

	uint32_t root_offset;
};

/*
packed_node {
	packed ((8bit_chars_count << 1) | have_16bit_chars);
	uint8_t 8bit_chars[8bit_chars_count];
	uint32_t idx[8bit_chars_count];
	if (have_16bit_chars) {
		packed 16bit_chars_count;
		uint16_t 16bit_chars[16bit_chars_count];
		uint32_t idx[16bit_chars_count];
	}
}
*/

#endif

Index: squat-trie.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/plugins/fts-squat/squat-trie.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- squat-trie.c	16 Jan 2007 17:00:41 -0000	1.13
+++ squat-trie.c	24 Jan 2007 14:41:28 -0000	1.14
@@ -13,6 +13,7 @@
 #include "unichar.h"
 #include "squat-uidlist.h"
 #include "squat-trie.h"
+#include "squat-trie-private.h"
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -100,32 +101,6 @@
 	unsigned int node_count;
 };
 
-struct squat_trie_header {
-	uint8_t version;
-	uint8_t unused[3];
-
-	uint32_t uidvalidity;
-	uint32_t used_file_size;
-	uint32_t deleted_space;
-	uint32_t node_count;
-	uint32_t modify_counter;
-
-	uint32_t root_offset;
-};
-
-/*
-packed_node {
-	packed ((8bit_chars_count << 1) | have_16bit_chars);
-	uint8_t 8bit_chars[8bit_chars_count];
-	uint32_t idx[8bit_chars_count];
-	if (have_16bit_chars) {
-		packed 16bit_chars_count;
-		uint16_t 16bit_chars[16bit_chars_count];
-		uint32_t idx[16bit_chars_count];
-	}
-}
-*/
-
 struct trie_node {
 	/* new characters have been added to this node */
 	uint8_t resized:1;
@@ -407,6 +382,9 @@
 	chars8_offset = p - trie->const_mmap_base;
 	chars8_size = chars8_count * (sizeof(uint8_t) + sizeof(uint32_t));
 
+	if (trie_map_area(trie, chars8_offset, chars8_size + 8) < 0)
+		return -1;
+
 	if (chars8_count > MAX_8BIT_CHAR_COUNT ||
 	    chars8_offset + chars8_size > trie->mmap_size) {
 		squat_trie_set_corrupted(trie, "trie offset broken");
@@ -421,9 +399,6 @@
 	chars8_memsize = ALIGN(alloced_chars8_count * sizeof(uint8_t)) +
 		alloced_chars8_count * idx_size;
 
-	if (trie_map_area(trie, chars8_offset, chars8_size + 8) < 0)
-		return -1;
-
 	if ((num & 1) == 0) {
 		/* no 16bit chars */
 		chars16_count = 0;
@@ -482,7 +457,7 @@
 		if (alloced_chars8_count != chars8_count)
 			trie_map_fix_fast_node(node, chars8_count);
 		if (chars16_count == 0)
-			end_offset = &src_idx[alloced_chars8_count];
+			end_offset = &src_idx[chars8_count];
 		else {
 			src_idx = CONST_PTR_OFFSET(chars16_src,
 						   chars16_count *
@@ -1128,6 +1103,10 @@
 					  &children[char_idx]) < 0)
 				return -1;
 		}
+
+		if (children[char_idx] == NULL)
+			node->resized = TRUE;
+
 		ret = trie_insert_node(ctx, &children[char_idx],
 				       data + 1, uid, level + 1);
 		if (ret < 0)
@@ -1136,6 +1115,10 @@
 			node->modified = TRUE;
 	} else {
 		uint32_t *uid_lists = (uint32_t *)children;
+
+		if (uid_lists[char_idx] == 0)
+			node->resized = TRUE;
+
 		if (squat_uidlist_add(trie->uidlist, &uid_lists[char_idx],
 				      uid) < 0)
 			return -1;
@@ -1456,7 +1439,7 @@
 		offset++;
 	}
 
-	if (node->resized && node->orig_size != trie->buf->used) {
+	if (node->resized && node->orig_size < trie->buf->used) {
 		/* append to end of file. the parent node is written later. */
 		node->file_offset = offset;
 		o_stream_send(ctx->output, trie->buf->data, trie->buf->used);



More information about the dovecot-cvs mailing list