sfeed

simple feed reader - forked from git.codemadness.org/sfeed
git clone git://src.gearsix.net/sfeed
Log | Files | Refs | Atom | README | LICENSE

commit 4d4ae4d724ad54773d28b486575ee950aff6ca22
parent 98505a150c116df12c96621d3de17efcc703bf4f
Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date:   Thu, 27 Apr 2017 14:32:18 +0200

improve gettag()

Diffstat:
Msfeed.c | 39+++++++++++++++++++++------------------
1 file changed, 21 insertions(+), 18 deletions(-)

diff --git a/sfeed.c b/sfeed.c @@ -122,8 +122,7 @@ static FeedTag rsstags[] = { { STRP("link"), RSSTagLink }, { STRP("media:description"), RSSTagMediaDescription }, { STRP("pubdate"), RSSTagPubdate }, - { STRP("title"), RSSTagTitle }, - { NULL, 0, -1 } + { STRP("title"), RSSTagTitle } }; /* Atom, alphabetical order */ static FeedTag atomtags[] = { @@ -137,8 +136,7 @@ static FeedTag atomtags[] = { { STRP("published"), AtomTagPublished }, { STRP("summary"), AtomTagSummary }, { STRP("title"), AtomTagTitle }, - { STRP("updated"), AtomTagUpdated }, - { NULL, 0, -1 } + { STRP("updated"), AtomTagUpdated } }; /* map tagid type to RSS/Atom field */ @@ -176,25 +174,30 @@ static XMLParser parser; /* XML parser state */ static enum TagId gettag(enum FeedType feedtype, const char *name, size_t namelen) { - const FeedTag *tags; size_t i; - /* optimization: these are always non-matching */ - if (namelen < 2 || namelen > 17) - return TagUnknown; - switch (feedtype) { - case FeedTypeRSS: tags = &rsstags[0]; break; - case FeedTypeAtom: tags = &atomtags[0]; break; - default: return TagUnknown; - } + case FeedTypeRSS: + /* optimization: these are always non-matching */ + if (namelen < 4 || namelen > 17) + return TagUnknown; - /* TODO: test if checking for sort order matters performance-wise */ - for (i = 0; tags[i].name; i++) - if (istag(tags[i].name, tags[i].len, name, namelen)) - return tags[i].id; + for (i = 0; i < sizeof(rsstags) / sizeof(rsstags[0]); i++) + if (istag(rsstags[i].name, rsstags[i].len, name, namelen)) + return rsstags[i].id; + return TagUnknown; + case FeedTypeAtom: + /* optimization: these are always non-matching */ + if (namelen < 2 || namelen > 17) + return TagUnknown; - return TagUnknown; + for (i = 0; i < sizeof(atomtags) / sizeof(atomtags[0]); i++) + if (istag(atomtags[i].name, atomtags[i].len, name, namelen)) + return atomtags[i].id; + return TagUnknown; + default: + return TagUnknown; + } } /* Clear string only; don't free, prevents unnecessary reallocation. */