[evolution] Move EPoolv back to Evolution from libedataserver.
- From: Matthew Barnes <mbarnes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution] Move EPoolv back to Evolution from libedataserver.
- Date: Wed, 31 Mar 2010 20:48:33 +0000 (UTC)
commit aac92ccc526ce5cbbd7af8836cd1fb7a57ab0bae
Author: Matthew Barnes <mbarnes redhat com>
Date: Wed Mar 31 16:32:19 2010 -0400
Move EPoolv back to Evolution from libedataserver.
MessageList is the only thing still using it.
EMemPool is gone now, so it uses CamelMemPool instead (same thing).
doc/reference/shell/eshell-docs.sgml | 1 +
doc/reference/shell/eshell-sections.txt | 10 ++
e-util/Makefile.am | 2 +
e-util/e-poolv.c | 146 +++++++++++++++++++++++++++++++
e-util/e-poolv.h | 41 +++++++++
mail/message-list.c | 3 +-
6 files changed, 201 insertions(+), 2 deletions(-)
---
diff --git a/doc/reference/shell/eshell-docs.sgml b/doc/reference/shell/eshell-docs.sgml
index 2556a58..6101932 100644
--- a/doc/reference/shell/eshell-docs.sgml
+++ b/doc/reference/shell/eshell-docs.sgml
@@ -37,6 +37,7 @@
<xi:include href="xml/e-html-utils.xml"/>
<xi:include href="xml/e-icon-factory.xml"/>
<xi:include href="xml/e-logger.xml"/>
+ <xi:include href="xml/e-poolv.xml"/>
<xi:include href="xml/e-print.xml"/>
<xi:include href="xml/e-selection.xml"/>
<xi:include href="xml/e-signature.xml"/>
diff --git a/doc/reference/shell/eshell-sections.txt b/doc/reference/shell/eshell-sections.txt
index 7f09d4e..7ee56ab 100644
--- a/doc/reference/shell/eshell-sections.txt
+++ b/doc/reference/shell/eshell-sections.txt
@@ -546,6 +546,16 @@ EModulePrivate
</SECTION>
<SECTION>
+<FILE>e-poolv</FILE>
+<TITLE>EPoolv</TITLE>
+EPoolv
+e_poolv_new
+e_poolv_set
+e_poolv_get
+e_poolv_destroy
+</SECTION>
+
+<SECTION>
<FILE>e-print</FILE>
<TITLE>Printing</TITLE>
e_print_operation_new
diff --git a/e-util/Makefile.am b/e-util/Makefile.am
index 3a9c723..c6ed8b4 100644
--- a/e-util/Makefile.am
+++ b/e-util/Makefile.am
@@ -36,6 +36,7 @@ eutilinclude_HEADERS = \
e-mktemp.h \
e-module.h \
e-non-intrusive-error-dialog.h \
+ e-poolv.h \
e-print.h \
e-plugin.h \
e-plugin-ui.h \
@@ -114,6 +115,7 @@ libeutil_la_SOURCES = \
e-mktemp.c \
e-module.c \
e-non-intrusive-error-dialog.c \
+ e-poolv.c \
e-plugin.c \
e-plugin-ui.c \
e-plugin-util.c \
diff --git a/e-util/e-poolv.c b/e-util/e-poolv.c
new file mode 100644
index 0000000..acd0a1a
--- /dev/null
+++ b/e-util/e-poolv.c
@@ -0,0 +1,146 @@
+/*
+ * e-poolv.c
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) version 3.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with the program; if not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+#include "e-poolv.h"
+
+#include <string.h>
+#include <camel/camel.h>
+
+struct _EPoolv {
+ guchar length;
+ gchar *s[1];
+};
+
+static GHashTable *poolv_pool;
+static CamelMemPool *poolv_mempool;
+
+G_LOCK_DEFINE_STATIC (poolv);
+
+/**
+ * e_poolv_new:
+ * @size: The number of elements in the poolv, maximum of 254 elements.
+ *
+ * Create a new #EPoolv: a string vector which shares a global string
+ * pool. An #EPoolv can be used to work with arrays of strings which
+ * save memory by eliminating duplicated allocations of the same string.
+ *
+ * This is useful when you have a log of read-only strings that do not
+ * go away and are duplicated a lot, such as email headers.
+ *
+ * Returns: a new #EPoolv
+ **/
+EPoolv *
+e_poolv_new (guint size)
+{
+ EPoolv *poolv;
+
+ g_return_val_if_fail (size < 255, NULL);
+
+ poolv = g_malloc0 (sizeof (*poolv) + (size - 1) * sizeof (gchar *));
+ poolv->length = size;
+
+ G_LOCK (poolv);
+
+ if (!poolv_pool)
+ poolv_pool = g_hash_table_new (g_str_hash, g_str_equal);
+
+ if (!poolv_mempool)
+ poolv_mempool = camel_mempool_new (
+ 32 * 1024, 512, CAMEL_MEMPOOL_ALIGN_BYTE);
+
+ G_UNLOCK (poolv);
+
+ return poolv;
+}
+
+/**
+ * e_poolv_set:
+ * @poolv: pooled string vector
+ * @index: index in vector of string
+ * @str: string to set
+ * @freeit: whether the caller is releasing its reference to the
+ * string
+ *
+ * Set a string vector reference. If the caller will no longer be
+ * referencing the string, freeit should be TRUE. Otherwise, this
+ * will duplicate the string if it is not found in the pool.
+ *
+ * Returns: @poolv
+ **/
+EPoolv *
+e_poolv_set (EPoolv *poolv, gint index, gchar *str, gint freeit)
+{
+ g_return_val_if_fail (poolv != NULL, NULL);
+ g_return_val_if_fail (index >= 0 && index < poolv->length, NULL);
+
+ if (!str) {
+ poolv->s[index] = NULL;
+ return poolv;
+ }
+
+ G_LOCK (poolv);
+
+ if ((poolv->s[index] = g_hash_table_lookup (poolv_pool, str)) != NULL) {
+ } else {
+ poolv->s[index] = camel_mempool_strdup (poolv_mempool, str);
+ g_hash_table_insert (poolv_pool, poolv->s[index], poolv->s[index]);
+ }
+
+ G_UNLOCK (poolv);
+
+ if (freeit)
+ g_free (str);
+
+ return poolv;
+}
+
+/**
+ * e_poolv_get:
+ * @poolv: pooled string vector
+ * @index: index in vector of string
+ *
+ * Retrieve a string by index. This could possibly just be a macro.
+ *
+ * Since the pool is never freed, this string does not need to be
+ * duplicated, but should not be modified.
+ *
+ * Returns: string at that index.
+ **/
+const gchar *
+e_poolv_get (EPoolv *poolv, gint index)
+{
+ g_return_val_if_fail (poolv != NULL, NULL);
+ g_return_val_if_fail (index >= 0 && index < poolv->length, NULL);
+
+ return poolv->s[index] ? poolv->s[index] : "";
+}
+
+/**
+ * e_poolv_destroy:
+ * @poolv: pooled string vector to free
+ *
+ * Free a pooled string vector. This doesn't free the strings from
+ * the vector, however.
+ **/
+void
+e_poolv_destroy (EPoolv *poolv)
+{
+ g_return_if_fail (poolv != NULL);
+
+ g_free (poolv);
+}
diff --git a/e-util/e-poolv.h b/e-util/e-poolv.h
new file mode 100644
index 0000000..e3cfb31
--- /dev/null
+++ b/e-util/e-poolv.h
@@ -0,0 +1,41 @@
+/*
+ * e-poolv.h
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) version 3.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with the program; if not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+#ifndef E_POOLV_H
+#define E_POOLV_H
+
+/* This was moved out of libedataserver since only MessageList uses it. */
+
+#include <glib.h>
+
+G_BEGIN_DECLS
+
+typedef struct _EPoolv EPoolv;
+
+EPoolv * e_poolv_new (guint size);
+EPoolv * e_poolv_set (EPoolv *poolv,
+ gint index,
+ gchar *str,
+ gint freeit);
+const gchar * e_poolv_get (EPoolv *poolv,
+ gint index);
+void e_poolv_destroy (EPoolv *poolv);
+
+G_END_DECLS
+
+#endif /* E_POOLV_H */
diff --git a/mail/message-list.c b/mail/message-list.c
index ca3830b..88a7110 100644
--- a/mail/message-list.c
+++ b/mail/message-list.c
@@ -44,9 +44,8 @@
#include <camel/camel-vee-folder.h>
#include <camel/camel-string-utils.h>
-#include <libedataserver/e-memory.h>
-
#include "e-util/e-icon-factory.h"
+#include "e-util/e-poolv.h"
#include "e-util/e-profile-event.h"
#include "e-util/e-util-private.h"
#include "e-util/e-util.h"
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]