[gmime] Optimized g_mime_strdup_trim() and updated parser to use it
- From: Jeffrey Stedfast <fejj src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gmime] Optimized g_mime_strdup_trim() and updated parser to use it
- Date: Mon, 20 Feb 2012 17:03:28 +0000 (UTC)
commit 5a335729ddb4e8dcea2b5a318d4541e17145fb3f
Author: Jeffrey Stedfast <fejj gnome org>
Date: Mon Feb 20 12:02:46 2012 -0500
Optimized g_mime_strdup_trim() and updated parser to use it
2012-02-20 Jeffrey Stedfast <fejj gnome org>
* gmime/gmime-common.c (g_mime_strdup_trim): Optimized.
* gmime/gmime-parser.c (header_parse): Use g_mime_strdup_trim()
instead of reimplementing the same logic here.
ChangeLog | 7 +++++++
gmime/gmime-common.c | 12 ++++--------
gmime/gmime-parser.c | 26 ++++----------------------
3 files changed, 15 insertions(+), 30 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index ef67ef8..483be7d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
2012-02-20 Jeffrey Stedfast <fejj gnome org>
+ * gmime/gmime-common.c (g_mime_strdup_trim): Optimized.
+
+ * gmime/gmime-parser.c (header_parse): Use g_mime_strdup_trim()
+ instead of reimplementing the same logic here.
+
+2012-02-20 Jeffrey Stedfast <fejj gnome org>
+
* gmime/gmime-parser.c: Instead of filtering Content-* headers
inside GMimeObject subclasses, filter them in the parser. This way
header fetching works as expected in subparts which might have
diff --git a/gmime/gmime-common.c b/gmime/gmime-common.c
index 9cc6a21..ab4c0f8 100644
--- a/gmime/gmime-common.c
+++ b/gmime/gmime-common.c
@@ -68,7 +68,8 @@ char *
g_mime_strdup_trim (const char *str)
{
register const char *inptr = str;
- const char *start, *end;
+ register const char *end;
+ const char *start;
while (is_lwsp (*inptr))
inptr++;
@@ -77,13 +78,8 @@ g_mime_strdup_trim (const char *str)
end = inptr;
while (*inptr) {
- while (*inptr && !is_lwsp (*inptr))
- inptr++;
-
- end = inptr;
-
- while (is_lwsp (*inptr))
- inptr++;
+ if (!is_lwsp (*inptr++))
+ end = inptr;
}
return g_strndup (start, (size_t) (end - start));
diff --git a/gmime/gmime-parser.c b/gmime/gmime-parser.c
index 36932ad..71997e7 100644
--- a/gmime/gmime-parser.c
+++ b/gmime/gmime-parser.c
@@ -34,6 +34,7 @@
#include "gmime-parse-utils.h"
#include "gmime-stream-mem.h"
#include "gmime-multipart.h"
+#include "gmime-common.h"
#include "gmime-part.h"
#if GLIB_MAJOR_VERSION > 2 || (GLIB_MAJOR_VERSION == 2 && GLIB_MINOR_VERSION >= 14)
@@ -916,10 +917,8 @@ static void
header_parse (GMimeParser *parser, HeaderRaw **tail)
{
struct _GMimeParserPrivate *priv = parser->priv;
- register char *inptr, *end;
+ register char *inptr;
HeaderRaw *header;
- char *start;
- size_t hlen;
*priv->headerptr = '\0';
inptr = priv->headerbuf;
@@ -938,28 +937,11 @@ header_parse (GMimeParser *parser, HeaderRaw **tail)
return;
}
- hlen = inptr - priv->headerbuf;
-
header = g_slice_new (HeaderRaw);
header->next = NULL;
- header->name = g_strndup (priv->headerbuf, hlen);
-
- /* skip over leading lwsp */
- inptr++;
- while (is_lwsp (*inptr))
- inptr++;
-
- /* cut trailing lwsp */
- start = inptr;
- end = inptr;
-
- while (*inptr) {
- if (!is_lwsp (*inptr++))
- end = inptr;
- }
-
- header->value = g_strndup (start, (size_t) (end - start));
+ header->name = g_strndup (priv->headerbuf, (size_t) (inptr - priv->headerbuf));
+ header->value = g_mime_strdup_trim (inptr + 1);
header->offset = priv->header_offset;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]