From d95b00a4d606b97469fb38c69de66915ae9a0dd0 Mon Sep 17 00:00:00 2001 From: waker Date: Tue, 26 Apr 2011 22:31:06 +0200 Subject: optimized search --- plmeta.c | 55 +++++++++++++++++++++++++++---------------------------- 1 file changed, 27 insertions(+), 28 deletions(-) (limited to 'plmeta.c') diff --git a/plmeta.c b/plmeta.c index 6b287637..36e289e6 100644 --- a/plmeta.c +++ b/plmeta.c @@ -30,6 +30,8 @@ void pl_add_meta (playItem_t *it, const char *key, const char *value) { LOCK; // check if it's already set + DB_metaInfo_t *normaltail = NULL; + DB_metaInfo_t *propstart = NULL; DB_metaInfo_t *tail = NULL; DB_metaInfo_t *m = it->meta; while (m) { @@ -38,6 +40,15 @@ pl_add_meta (playItem_t *it, const char *key, const char *value) { UNLOCK; return; } + // find end of normal metadata + if (!normaltail && (m->key[0] == ':' || m->key[0] == '_')) { + normaltail = tail; + propstart = m; + if (key[0] != ':' && key[0] != '_') { + break; + } + } + // find end of properties tail = m; m = m->next; } @@ -46,40 +57,28 @@ pl_add_meta (playItem_t *it, const char *key, const char *value) { if (!value || !*value) { UNLOCK; return; -#if 0 - if (!strcasecmp (key, "title")) { - // cut filename without path and extension - const char *pext = pl_find_meta (it, ":URI") + strlen (pl_find_meta (it, ":URI")) - 1; - while (pext >= pl_find_meta (it, ":URI") && *pext != '.') { - pext--; - } - const char *pname = pext; - while (pname >= pl_find_meta (it, ":URI") && *pname != '/') { - pname--; - } - if (*pname == '/') { - pname++; - } - strncpy (str, pname, pext-pname); - str[pext-pname] = 0; - value = str; - } - else { - UNLOCK; - return; - } -#endif } m = malloc (sizeof (DB_metaInfo_t)); memset (m, 0, sizeof (DB_metaInfo_t)); - m->key = metacache_add_string (key); //key; - m->value = metacache_add_string (value); //strdup (value); + m->key = metacache_add_string (key); + m->value = metacache_add_string (value); - if (tail) { - tail->next = m; + if (key[0] == ':' || key[0] == '_') { + if (tail) { + tail->next = m; + } + else { + it->meta = m; + } } else { - it->meta = m; + m->next = propstart; + if (normaltail) { + normaltail->next = m; + } + else { + it->meta = m; + } } UNLOCK; } -- cgit v1.2.3