[Evolution-hackers] mmap patch



Well, I figured out why you're getting alignment problems... you're
using int* pointers to decode stuff. You need to use a char*

Secondly, your code is just really gross:

- Why do you have a filepos pointer? it's completely unnecessary.

- Why do you use a ptr32 thing? That's gross. There are far cleaner ways
of doing this... it's also the source of your alignment problems.

- Why do you have ::needs_free and ::uid_needs_free? Please find another
way to do this. This is a horrible hack.

Attached you'll find the beginnings of a much cleaner implementation of
the mmap approach.



-- 
Jeffrey Stedfast
Evolution Hacker - Novell, Inc.
fejj novell com  - www.novell.com
? camel-gpg-context.c.gpg
? camel-mime-tables.c
? camel_folder_summary_with_mmap_fixes11.txt
? const-charset-map.patch
? mmap.patch
? pgp-filter.patch
? pstring.patch
? providers/imap4/272058.patch
? providers/imap4/imap4-sockopt.patch
? providers/local/largefile-mbox.patch
? providers/pop3/pop3-folder.c
Index: camel-file-utils.c
===================================================================
RCS file: /cvs/gnome/evolution-data-server/camel/camel-file-utils.c,v
retrieving revision 1.17
diff -u -r1.17 camel-file-utils.c
--- camel-file-utils.c	2 Jun 2006 00:52:29 -0000	1.17
+++ camel-file-utils.c	19 Jul 2006 20:32:13 -0000
@@ -262,18 +262,18 @@
 int
 camel_file_util_encode_string (FILE *out, const char *str)
 {
-	register int len;
-
-	if (str == NULL)
-		return camel_file_util_encode_uint32 (out, 1);
+	size_t len;
 	
-	if ((len = strlen (str)) > 65536)
-		len = 65536;
+	if (str == NULL)
+		return camel_file_util_encode_size_t (out, 0);
 	
-	if (camel_file_util_encode_uint32 (out, len+1) == -1)
+	len = strlen (str);
+	if (camel_file_util_encode_size_t (out, len + 1) == -1)
 		return -1;
-	if (len == 0 || fwrite (str, len, 1, out) == 1)
+	
+	if (fwrite (str, len + 1, 1, out) == 1)
 		return 0;
+	
 	return -1;
 }
 
@@ -290,29 +290,317 @@
 int
 camel_file_util_decode_string (FILE *in, char **str)
 {
-	guint32 len;
-	register char *ret;
-
-	if (camel_file_util_decode_uint32 (in, &len) == -1) {
+	size_t len;
+	
+	if (camel_file_util_decode_size_t (in, &len) == -1) {
 		*str = NULL;
 		return -1;
 	}
-
-	len--;
-	if (len > 65536) {
+	
+	if (len == 0) {
+		*str = NULL;
+		return 0;
+	}
+	
+	if (!(*str = g_try_malloc (len))) {
 		*str = NULL;
 		return -1;
 	}
-
-	ret = g_malloc (len+1);
-	if (len > 0 && fread (ret, len, 1, in) != 1) {
-		g_free (ret);
+	
+	if (fread (*str, len, 1, in) != 1) {
+		g_free (*str);
 		*str = NULL;
 		return -1;
 	}
+	
+	return 0;
+}
+
+
+/**
+ * camel_mmap_util_encode_uint32:
+ * @out: file to output to
+ * @value: value to output
+ * 
+ * Utility function to save an uint32 to a file.
+ * 
+ * Return value: 0 on success, -1 on error.
+ **/
+int
+camel_mmap_util_encode_uint32 (char **out, guint32 value)
+{
+	char *outptr = *out;
+	unsigned char c;
+	int i;
+	
+	for (i = 28; i > 0; i -= 7) {
+		if (value >= (1 << i)) {
+			c = (value >> i) & 0x7f;
+			*outptr++ = c;
+		}
+	}
+	
+	c = value & 0x7f;
+	*outptr++ = c | 0x80;
+	
+	*out = outptr;
+	
+	return 0;
+}
+
+
+/**
+ * camel_mmap_util_decode_uint32:
+ * @in: file to read from
+ * @dest: pointer to a variable to store the value in
+ * 
+ * Retrieve an encoded uint32 from a file.
+ * 
+ * Return value: 0 on success, -1 on error.  @*dest will contain the
+ * decoded value.
+ **/
+int
+camel_mmap_util_decode_uint32 (const char **in, guint32 *dest)
+{
+	const char *inptr = *in;
+        guint32 value = 0;
+	unsigned char v;
+	
+        /* until we get the last byte, keep decoding 7 bits at a time */
+	while (((v = *inptr++) & 0x80) == 0) {
+		value |= v;
+		value <<= 7;
+	}
+	
+	*dest = value | (v & 0x7f);
+	*in = inptr;
+	
+        return 0;
+}
+
+
+/**
+ * camel_mmap_util_encode_fixed_int32:
+ * @out: file to output to
+ * @value: value to output
+ * 
+ * Encode a gint32, performing no compression, but converting
+ * to network order.
+ * 
+ * Return value: 0 on success, -1 on error.
+ **/
+int
+camel_mmap_util_encode_fixed_int32 (char **out, gint32 value)
+{
+	gint32 save;
+	
+	save = GINT32_TO_LE (value);
+	memcpy (*out, &save, sizeof (gint32));
+	*out = *out + sizeof (gint32);
+	
+	return 0;
+}
+
+
+/**
+ * camel_mmap_util_decode_fixed_int32:
+ * @in: file to read from
+ * @dest: pointer to a variable to store the value in
+ * 
+ * Retrieve a gint32.
+ * 
+ * Return value: 0 on success, -1 on error.
+ **/
+int
+camel_mmap_util_decode_fixed_int32 (const char **in, gint32 *dest)
+{
+	const char *inptr = *in;
+	gint32 value = 0;
+	int i;
+	
+	for (i = 0; i < sizeof (guint32); i++, inptr++, value <<= 8)
+		value |= *inptr;
+	
+	*dest = GUINT32_FROM_LE (value);
+	*in = inptr;
+	
+	return 0;
+}
+
+#define MMAP_ENCODE_T(type)						\
+int									\
+camel_mmap_util_encode_##type(char **out, type value)			\
+{									\
+	type save;							\
+									\			
+	switch (sizeof (type)) {					\
+	case 4:								\
+		save = GUINT32_TO_LE (value);				\
+		break;							\
+	case 8:								\
+		save = GUINT64_TO_LE (value);				\
+		break;							\
+	default:							\
+		save = value;						\
+	}								\
+									\
+	memcpy (*out, &save, sizeof (type));				\
+	*out = *out + sizeof (type);					\
+									\
+	return 0;							\
+}
+
+#define MMAP_DECODE_T(type)						\
+int									\
+camel_mmap_util_decode_##type(const char **in, type *dest)		\
+{									\
+	const char *inptr = *in;					\
+	type value = 0;							\
+	int i;								\
+									\
+	for (i = 0; i < sizeof (type); i++, inptr++, value <<= 8)	\
+		value |= *inptr;					\
+									\
+	switch (sizeof (type)) {					\
+	case 4:								\
+		*dest = GUINT32_FROM_LE (value);			\
+		break;							\
+	case 8:								\
+		*dest = GUINT64_FROM_LE (value);			\
+		break;							\
+	default:							\
+		*dest = value;						\
+	}								\
+									\
+	*in = inptr;							\
+									\
+	return 0;							\
+}
+
+
+/**
+ * camel_mmap_util_encode_time_t:
+ * @out: file to output to
+ * @value: value to output
+ * 
+ * Encode a time_t value to the file.
+ * 
+ * Return value: 0 on success, -1 on error.
+ **/
+MMAP_ENCODE_T(time_t)
+
+/**
+ * camel_mmap_util_decode_time_t:
+ * @in: file to read from
+ * @dest: pointer to a variable to store the value in
+ * 
+ * Decode a time_t value.
+ * 
+ * Return value: 0 on success, -1 on error.
+ **/
+MMAP_DECODE_T(time_t)
+
+/**
+ * camel_mmap_util_encode_off_t:
+ * @out: file to output to
+ * @value: value to output
+ * 
+ * Encode an off_t type.
+ * 
+ * Return value: 0 on success, -1 on error.
+ **/
+MMAP_ENCODE_T(off_t)
+
+
+/**
+ * camel_mmap_util_decode_off_t:
+ * @in: file to read from
+ * @dest: pointer to a variable to put the value in
+ * 
+ * Decode an off_t type.
+ * 
+ * Return value: 0 on success, -1 on failure.
+ **/
+MMAP_DECODE_T(off_t)
+
+/**
+ * camel_mmap_util_encode_size_t:
+ * @out: file to output to
+ * @value: value to output
+ * 
+ * Encode an size_t type.
+ * 
+ * Return value: 0 on success, -1 on error.
+ **/
+MMAP_ENCODE_T(size_t)
+
 
-	ret[len] = 0;
-	*str = ret;
+/**
+ * camel_mmap_util_decode_size_t:
+ * @in: file to read from
+ * @dest: pointer to a variable to put the value in
+ * 
+ * Decode an size_t type.
+ * 
+ * Return value: 0 on success, -1 on failure.
+ **/
+MMAP_DECODE_T(size_t)
+
+
+/**
+ * camel_mmap_util_encode_string:
+ * @out: file to output to
+ * @str: value to output
+ * 
+ * Encode a normal string and save it in the output file.
+ * 
+ * Return value: 0 on success, -1 on error.
+ **/
+int
+camel_mmap_util_encode_string (char **out, const char *str)
+{
+	size_t len;
+	
+	if (str == NULL)
+		return camel_mmap_util_encode_size_t (out, 0);
+	
+	len = strlen (str);
+	if (camel_mmap_util_encode_size_t (out, len + 1) == -1)
+		return -1;
+	
+	memcpy (*out, str, len + 1);
+	*out = *out + len + 1;
+	
+	return 0;
+}
+
+
+/**
+ * camel_mmap_util_decode_string:
+ * @in: file to read from
+ * @str: pointer to a variable to store the value in
+ * 
+ * Decode a normal string from the input file.
+ * 
+ * Return value: 0 on success, -1 on error.
+ **/
+int
+camel_mmap_util_decode_string (const char **in, const char **str)
+{
+	size_t len;
+	
+	if (camel_mmap_util_decode_size_t (in, &len) == -1) {
+		*str = NULL;
+		return -1;
+	}
+	
+	if (len != 0) {
+		*str = *in;
+		*in = *in + len;
+	} else {
+		*str = NULL;
+	}
+	
 	return 0;
 }
 
@@ -334,7 +622,7 @@
 #else
 	const char *unsafe_chars = "/?()'*";
 #endif
-
+	
 	if (name == NULL)
 		return NULL;
 	
Index: camel-file-utils.h
===================================================================
RCS file: /cvs/gnome/evolution-data-server/camel/camel-file-utils.h,v
retrieving revision 1.11
diff -u -r1.11 camel-file-utils.h
--- camel-file-utils.h	10 Jan 2006 07:56:46 -0000	1.11
+++ camel-file-utils.h	19 Jul 2006 20:32:13 -0000
@@ -55,6 +55,19 @@
 int camel_file_util_encode_string (FILE *out, const char *);
 int camel_file_util_decode_string (FILE *in, char **);
 
+int camel_mmap_util_encode_fixed_int32 (char **out, gint32);
+int camel_mmap_util_decode_fixed_int32 (const char **in, gint32 *);
+int camel_mmap_util_encode_uint32 (char **out, guint32);
+int camel_mmap_util_decode_uint32 (const char **in, guint32 *);
+int camel_mmap_util_encode_time_t (char **out, time_t);
+int camel_mmap_util_decode_time_t (const char **in, time_t *);
+int camel_mmap_util_encode_off_t (char **out, off_t);
+int camel_mmap_util_decode_off_t (const char **in, off_t *);
+int camel_mmap_util_encode_size_t (char **out, size_t);
+int camel_mmap_util_decode_size_t (const char **in, size_t *);
+int camel_mmap_util_encode_string (char **out, const char *);
+int camel_mmap_util_decode_string (const char **in, const char **);
+
 char *camel_file_util_safe_filename (const char *name);
 
 /* Code that intends to be portable to Win32 should use camel_read()
Index: camel-folder-summary.c
===================================================================
RCS file: /cvs/gnome/evolution-data-server/camel/camel-folder-summary.c,v
retrieving revision 1.149
diff -u -r1.149 camel-folder-summary.c
--- camel-folder-summary.c	6 Jul 2006 19:43:46 -0000	1.149
+++ camel-folder-summary.c	19 Jul 2006 20:32:13 -0000
@@ -137,7 +137,9 @@
 	s->flags = 0;
 	s->time = 0;
 	s->nextuid = 1;
-
+	
+	s->map = NULL;
+	
 	s->messages = g_ptr_array_new();
 	s->messages_uid = g_hash_table_new(g_str_hash, g_str_equal);
 	
@@ -150,7 +152,7 @@
 
 static void free_o_name(void *key, void *value, void *data)
 {
-	camel_object_unref((CamelObject *)value);
+	camel_object_unref (value);
 	g_free(key);
 }
 
@@ -161,7 +163,10 @@
 	CamelFolderSummary *s = (CamelFolderSummary *)obj;
 
 	p = _PRIVATE(obj);
-
+	
+	if (s->map)
+		g_mapped_file_free (s->map);
+	
 	camel_folder_summary_clear(s);
 	g_ptr_array_free(s->messages, TRUE);
 	g_hash_table_destroy(s->messages_uid);
@@ -177,22 +182,22 @@
 		e_memchunk_destroy(s->content_info_chunks);
 
 	if (p->filter_index)
-		camel_object_unref((CamelObject *)p->filter_index);
+		camel_object_unref (p->filter_index);
 	if (p->filter_64)
-		camel_object_unref((CamelObject *)p->filter_64);
+		camel_object_unref (p->filter_64);
 	if (p->filter_qp)
-		camel_object_unref((CamelObject *)p->filter_qp);
+		camel_object_unref (p->filter_qp);
 	if (p->filter_uu)
-		camel_object_unref((CamelObject *)p->filter_uu);
+		camel_object_unref (p->filter_uu);
 	if (p->filter_save)
-		camel_object_unref((CamelObject *)p->filter_save);
+		camel_object_unref (p->filter_save);
 	if (p->filter_html)
-		camel_object_unref((CamelObject *)p->filter_html);
+		camel_object_unref (p->filter_html);
 
 	if (p->filter_stream)
-		camel_object_unref((CamelObject *)p->filter_stream);
+		camel_object_unref (p->filter_stream);
 	if (p->index)
-		camel_object_unref((CamelObject *)p->index);
+		camel_object_unref (p->index);
 	
 	g_mutex_free(p->summary_lock);
 	g_mutex_free(p->io_lock);
@@ -499,24 +504,22 @@
 
 /* loads the content descriptions, recursively */
 static CamelMessageContentInfo *
-perform_content_info_load(CamelFolderSummary *s, FILE *in)
+perform_content_info_load(CamelFolderSummary *s, const char **in)
 {
-	int i;
-	guint32 count;
 	CamelMessageContentInfo *ci, *part;
-
-	ci = ((CamelFolderSummaryClass *)(CAMEL_OBJECT_GET_CLASS(s)))->content_info_load(s, in);
-	if (ci == NULL)
+	guint32 count;
+	int i;
+	
+	if (!(ci = ((CamelFolderSummaryClass *)(CAMEL_OBJECT_GET_CLASS(s)))->content_info_load(s, in)))
 		return NULL;
-
+	
 	if (camel_file_util_decode_uint32(in, &count) == -1 || count > 500) {
 		camel_folder_summary_content_info_free(s, ci);
 		return NULL;
 	}
 
-	for (i=0;i<count;i++) {
-		part = perform_content_info_load(s, in);
-		if (part) {
+	for (i = 0; i < count; i++) {
+		if ((part = perform_content_info_load(s, in))) {
 			my_list_append((struct _node **)&ci->childs, (struct _node *)part);
 			part->parent = ci;
 		} else {
@@ -525,6 +528,7 @@
 			return NULL;
 		}
 	}
+	
 	return ci;
 }
 
@@ -540,57 +544,61 @@
 int
 camel_folder_summary_load(CamelFolderSummary *s)
 {
-	FILE *in;
-	int i;
 	CamelMessageInfo *mi;
-
+	const char *inptr;
+	int i;
+	
 	if (s->summary_path == NULL)
 		return 0;
-
-	in = g_fopen(s->summary_path, "rb");
-	if (in == NULL)
+	
+	if ((fd = g_open (s->summary_path, O_RDWR, 0)) == -1)
 		return -1;
-
+	
 	CAMEL_SUMMARY_LOCK(s, io_lock);
-	if ( ((CamelFolderSummaryClass *)(CAMEL_OBJECT_GET_CLASS(s)))->summary_header_load(s, in) == -1)
+	
+	if (!s->map && !(s->map = g_mapped_file_new (s->summary_path, FALSE, NULL))) {
+		CAMEL_SUMMARY_UNLOCK (s, io_lock);
+		return -1;
+	}
+	
+	inptr = g_mapped_file_get_contents (s->map);
+	
+	if (((CamelFolderSummaryClass *)(CAMEL_OBJECT_GET_CLASS(s)))->summary_header_load (s, &inptr) == -1)
 		goto error;
-
+	
 	/* now read in each message ... */
-	for (i=0;i<s->saved_count;i++) {
-		mi = ((CamelFolderSummaryClass *)(CAMEL_OBJECT_GET_CLASS(s)))->message_info_load(s, in);
-
-		if (mi == NULL)
+	for (i = 0; i < s->saved_count; i++) {
+		if (!(mi = ((CamelFolderSummaryClass *)(CAMEL_OBJECT_GET_CLASS(s)))->message_info_load (s, &inptr)))
 			goto error;
-
+		
 		/* FIXME: this should be done differently, how i don't know */
 		if (s->build_content) {
-			((CamelMessageInfoBase *)mi)->content = perform_content_info_load(s, in);
-			if (((CamelMessageInfoBase *)mi)->content == NULL) {
-				camel_message_info_free(mi);
+			((CamelMessageInfoBase *) mi)->content = perform_content_info_load (s, &inptr);
+			if (((CamelMessageInfoBase *) mi)->content == NULL) {
+				camel_message_info_free (mi);
 				goto error;
 			}
 		}
-
-		camel_folder_summary_add(s, mi);
+		
+		camel_folder_summary_add (s, mi);
 	}
-
+	
 	CAMEL_SUMMARY_UNLOCK(s, io_lock);
 	
-	if (fclose (in) != 0)
-		return -1;
-
 	s->flags &= ~CAMEL_SUMMARY_DIRTY;
-
+	
 	return 0;
-
+	
 error:
 	if (errno != EINVAL)
 		g_warning ("Cannot load summary file: `%s': %s", s->summary_path, g_strerror (errno));
 	
+	g_mapped_file_free (s->map);
+	s->map = NULL;
+	
 	CAMEL_SUMMARY_UNLOCK(s, io_lock);
-	fclose (in);
 	s->flags |= ~CAMEL_SUMMARY_DIRTY;
-
+	
 	return -1;
 }
 
@@ -724,22 +732,24 @@
 int
 camel_folder_summary_header_load(CamelFolderSummary *s)
 {
-	FILE *in;
+	const char *inptr;
 	int ret;
-
+	
 	if (s->summary_path == NULL)
 		return 0;
-
-	in = g_fopen(s->summary_path, "rb");
-	if (in == NULL)
-		return -1;
-
+	
 	CAMEL_SUMMARY_LOCK(s, io_lock);
-	ret = ((CamelFolderSummaryClass *)(CAMEL_OBJECT_GET_CLASS(s)))->summary_header_load(s, in);
-	CAMEL_SUMMARY_UNLOCK(s, io_lock);
 	
-	fclose(in);
+	if (!s->map && !(s->map = g_mapped_file_new (s->summary_path, FALSE, NULL))) {
+		CAMEL_SUMMARY_UNLOCK (s, io_lock);
+		return -1;
+	}
+	
+	inptr = g_mapped_file_get_contents (s->map);
+	ret = ((CamelFolderSummaryClass *)(CAMEL_OBJECT_GET_CLASS (s)))->summary_header_load (s, &inptr);
+	CAMEL_SUMMARY_UNLOCK(s, io_lock);
 	s->flags &= ~CAMEL_SUMMARY_DIRTY;
+	
 	return ret;
 }
 
@@ -1271,43 +1281,45 @@
 int
 camel_folder_summary_encode_token(FILE *out, const char *str)
 {
+	int token = -1, i;
+	size_t len;
+	
 	io(printf("Encoding token: '%s'\n", str));
-
-	if (str == NULL) {
-		return camel_file_util_encode_uint32(out, 0);
-	} else {
-		int len = strlen(str);
-		int i, token=-1;
-
-		if (len <= 16) {
-			char lower[32];
-			char **match;
-
-			for (i=0;i<len;i++)
-				lower[i] = tolower(str[i]);
-			lower[i] = 0;
+	
+	if (str == NULL)
+		return camel_file_util_encode_uint32 (out, 0);
+	
+	len = strlen (str);
+	if (len <= 16) {
+		char lower[32];
+		char **match;
+		
+		for (i=0;i<len;i++)
+			lower[i] = tolower(str[i]);
+		lower[i] = 0;
 #ifdef USE_BSEARCH
-			match = bsearch(lower, tokens, tokens_len, sizeof(char *), (int (*)(const void *, const void *))token_search_cmp);
-			if (match)
-				token = match-tokens;
+		match = bsearch(lower, tokens, tokens_len, sizeof(char *), (int (*)(const void *, const void *))token_search_cmp);
+		if (match)
+			token = match-tokens;
 #else
-			for (i=0;i<tokens_len;i++) {
-				if (!strcmp(tokens[i], lower)) {
-					token = i;
-					break;
-				}
+		for (i = 0; i < tokens_len; i++) {
+			if (!strcmp (tokens[i], lower)) {
+				token = i;
+				break;
 			}
-#endif
-		}
-		if (token != -1) {
-			return camel_file_util_encode_uint32(out, token+1);
-		} else {
-			if (camel_file_util_encode_uint32(out, len+32) == -1)
-				return -1;
-			if (fwrite(str, len, 1, out) != 1)
-				return -1;
 		}
+#endif
 	}
+	
+	if (token != -1) {
+		return camel_file_util_encode_uint32(out, token+1);
+	} else {
+		if (camel_file_util_encode_uint32(out, len+32) == -1)
+			return -1;
+		if (fwrite(str, len, 1, out) != 1)
+			return -1;
+	}
+	
 	return 0;
 }
 
@@ -1390,13 +1402,11 @@
 }
 
 static int
-summary_header_load(CamelFolderSummary *s, FILE *in)
+summary_header_load(CamelFolderSummary *s, const char **in)
 {
-	fseek(in, 0, SEEK_SET);
-
 	io(printf("Loading header\n"));
 
-	if (camel_file_util_decode_fixed_int32(in, &s->version) == -1)
+	if (camel_mmap_util_decode_fixed_int32(in, &s->version) == -1)
 		return -1;
 
 	/* Legacy version check, before version 12 we have no upgrade knowledge */
@@ -1412,18 +1422,18 @@
 		io(printf("loading new-format summary\n"));
 
 	/* legacy version */
-	if (camel_file_util_decode_fixed_int32(in, &s->flags) == -1
-	    || camel_file_util_decode_fixed_int32(in, &s->nextuid) == -1
-	    || camel_file_util_decode_time_t(in, &s->time) == -1
-	    || camel_file_util_decode_fixed_int32(in, &s->saved_count) == -1) {
+	if (camel_mmap_util_decode_fixed_int32(in, &s->flags) == -1
+	    || camel_mmap_util_decode_fixed_int32(in, &s->nextuid) == -1
+	    || camel_mmap_util_decode_time_t(in, &s->time) == -1
+	    || camel_mmap_util_decode_fixed_int32(in, &s->saved_count) == -1) {
 		return -1;
 	}
 
 	/* version 13 */
 	if (s->version < 0x100 && s->version >= 13
-	    && (camel_file_util_decode_fixed_int32(in, &s->unread_count) == -1
-		|| camel_file_util_decode_fixed_int32(in, &s->deleted_count) == -1
-		|| camel_file_util_decode_fixed_int32(in, &s->junk_count) == -1)) {
+	    && (camel_mmap_util_decode_fixed_int32(in, &s->unread_count) == -1
+		|| camel_mmap_util_decode_fixed_int32(in, &s->deleted_count) == -1
+		|| camel_mmap_util_decode_fixed_int32(in, &s->junk_count) == -1)) {
 		return -1;
 	}
 
@@ -1682,82 +1692,74 @@
 }
 
 static CamelMessageInfo *
-message_info_load(CamelFolderSummary *s, FILE *in)
+message_info_load(CamelFolderSummary *s, const char **in)
 {
 	CamelMessageInfoBase *mi;
 	guint count;
 	int i;
-	char *subject, *from, *to, *cc, *mlist, *uid;
-
+	
 	mi = (CamelMessageInfoBase *)camel_message_info_new(s);
-
+	
 	io(printf("Loading message info\n"));
-
-	camel_file_util_decode_string(in, &uid);
-	camel_file_util_decode_uint32(in, &mi->flags);
-	camel_file_util_decode_uint32(in, &mi->size);
-	camel_file_util_decode_time_t(in, &mi->date_sent);
-	camel_file_util_decode_time_t(in, &mi->date_received);
-	camel_file_util_decode_string(in, &subject);
-	camel_file_util_decode_string(in, &from);
-	camel_file_util_decode_string(in, &to);
-	camel_file_util_decode_string(in, &cc);
-	camel_file_util_decode_string(in, &mlist);
 	
-	mi->uid = uid;
-	mi->subject = camel_pstring_add (subject, TRUE);
-	mi->from = camel_pstring_add (from, TRUE);
-	mi->to = camel_pstring_add (to, TRUE);
-	mi->cc = camel_pstring_add (cc, TRUE);
-	mi->mlist = camel_pstring_add (mlist, TRUE);
+	camel_mmap_util_decode_string (in, &mi->uid);
+	camel_mmap_util_decode_uint32 (in, &mi->flags);
+	camel_mmap_util_decode_uint32 (in, &mi->size);
+	camel_mmap_util_decode_time_t (in, &mi->date_sent);
+	camel_mmap_util_decode_time_t (in, &mi->date_received);
+	camel_mmap_util_decode_string (in, &mi->subject);
+	camel_mmap_util_decode_string (in, &mi->from);
+	camel_mmap_util_decode_string (in, &mi->to);
+	camel_mmap_util_decode_string (in, &mi->cc);
+	camel_mmap_util_decode_string (in, &mi->mlist);
 	
 	mi->content = NULL;
-
-	camel_file_util_decode_fixed_int32(in, &mi->message_id.id.part.hi);
-	camel_file_util_decode_fixed_int32(in, &mi->message_id.id.part.lo);
-
-	if (camel_file_util_decode_uint32(in, &count) == -1 || count > 500)
+	
+	camel_mmap_util_decode_fixed_int32 (in, &mi->message_id.id.part.hi);
+	camel_mmap_util_decode_fixed_int32 (in, &mi->message_id.id.part.lo);
+	
+	if (camel_mmap_util_decode_uint32 (in, &count) == -1 || count > 500)
 		goto error;
-
+	
 	if (count > 0) {
 		mi->references = g_malloc(sizeof(*mi->references) + ((count-1) * sizeof(mi->references->references[0])));
 		mi->references->size = count;
-		for (i=0;i<count;i++) {
-			camel_file_util_decode_fixed_int32(in, &mi->references->references[i].id.part.hi);
-			camel_file_util_decode_fixed_int32(in, &mi->references->references[i].id.part.lo);
+		for (i = 0; i < count; i++) {
+			camel_mmap_util_decode_fixed_int32 (in, &mi->references->references[i].id.part.hi);
+			camel_mmap_util_decode_fixed_int32 (in, &mi->references->references[i].id.part.lo);
 		}
 	}
-
-	if (camel_file_util_decode_uint32(in, &count) == -1 || count > 500)
+	
+	if (camel_mmap_util_decode_uint32 (in, &count) == -1 || count > 500)
 		goto error;
-
-	for (i=0;i<count;i++) {
+	
+	for (i = 0; i < count; i++) {
 		char *name;
-		if (camel_file_util_decode_string(in, &name) == -1 || name == NULL)
+		
+		if (camel_mmap_util_decode_string (in, &name) == -1 || name == NULL)
 			goto error;
-		camel_flag_set(&mi->user_flags, name, TRUE);
-		g_free(name);
+		
+		camel_flag_set (&mi->user_flags, name, TRUE);
 	}
-
-	if (camel_file_util_decode_uint32(in, &count) == -1 || count > 500)
+	
+	if (camel_mmap_util_decode_uint32 (in, &count) == -1 || count > 500)
 		goto error;
-
-	for (i=0;i<count;i++) {
+	
+	for (i = 0; i < count; i++) {
 		char *name, *value;
-		if (camel_file_util_decode_string(in, &name) == -1 || name == NULL
-		    || camel_file_util_decode_string(in, &value) == -1)
+		
+		if (camel_mmap_util_decode_string (in, &name) == -1 || name == NULL
+		    || camel_mmap_util_decode_string(in, &value) == -1)
 			goto error;
-		camel_tag_set(&mi->user_tags, name, value);
-		g_free(name);
-		g_free(value);
+		
+		camel_tag_set (&mi->user_tags, name, value);
 	}
-
-	if (!ferror(in))
-		return (CamelMessageInfo *)mi;
-
+	
+	return (CamelMessageInfo *) mi;
+	
 error:
 	camel_message_info_free((CamelMessageInfo *)mi);
-
+	
 	return NULL;
 }
 
Index: camel-folder-summary.h
===================================================================
RCS file: /cvs/gnome/evolution-data-server/camel/camel-folder-summary.h,v
retrieving revision 1.86
diff -u -r1.86 camel-folder-summary.h
--- camel-folder-summary.h	31 Aug 2005 04:21:56 -0000	1.86
+++ camel-folder-summary.h	19 Jul 2006 20:32:13 -0000
@@ -219,7 +219,9 @@
 
 	char *summary_path;
 	gboolean build_content;	/* do we try and parse/index the content, or not? */
-
+	
+	GMappedFile *map;
+	
 	GPtrArray *messages;	/* CamelMessageInfo's */
 	GHashTable *messages_uid; /* CamelMessageInfo's by uid */
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]