From f71ac4d479502738682f2328a6523d18be705ac9 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 13 Oct 2008 16:56:00 +0200 Subject: song: stat file in song_file_update(), don't use isMusic() isMusic() used to be a very inefficient function: with every invocation, it did another stat() on the specified file. There is only one caller, do the stat() there manually and use hasMusicSuffix() instead of isMusic(). --- src/ls.c | 12 ------------ src/ls.h | 3 --- src/song.c | 13 ++++++++----- 3 files changed, 8 insertions(+), 20 deletions(-) (limited to 'src') diff --git a/src/ls.c b/src/ls.c index 01614710f..a27bc821c 100644 --- a/src/ls.c +++ b/src/ls.c @@ -255,15 +255,3 @@ struct decoder_plugin *hasMusicSuffix(const char *utf8file, unsigned int next) return ret; } - -struct decoder_plugin *isMusic(const char *utf8file, time_t * mtime, - unsigned int next) -{ - if (isFile(utf8file, mtime)) { - struct decoder_plugin *plugin = hasMusicSuffix(utf8file, next); - if (plugin != NULL) - return plugin; - } - DEBUG("isMusic: %s is not a valid file\n", utf8file); - return NULL; -} diff --git a/src/ls.h b/src/ls.h index fdc61bd81..0eed1fe14 100644 --- a/src/ls.h +++ b/src/ls.h @@ -40,9 +40,6 @@ int isDir(const char *utf8name); struct decoder_plugin *hasMusicSuffix(const char *utf8file, unsigned int next); -struct decoder_plugin *isMusic(const char *utf8file, time_t * mtime, - unsigned int next); - int printRemoteUrlHandlers(struct client *client); int isFile(const char *utf8file, time_t * mtime); diff --git a/src/song.c b/src/song.c index 127d39eb4..a32d3920f 100644 --- a/src/song.c +++ b/src/song.c @@ -97,6 +97,7 @@ song_file_update(struct song *song) unsigned int next = 0; char path_max_tmp[MPD_PATH_MAX]; char abs_path[MPD_PATH_MAX]; + struct stat st; assert(song_is_file(song)); @@ -108,14 +109,16 @@ song_file_update(struct song *song) song->tag = NULL; } + if (stat(abs_path, &st) < 0) + return false; + + song->mtime = st.st_mtime; + while (song->tag == NULL && - (plugin = isMusic(abs_path, &(song->mtime), next++))) + (plugin = hasMusicSuffix(abs_path, next++))) song->tag = plugin->tag_dup(abs_path); - if (song->tag == NULL || song->tag->time < 0) - return false; - - return true; + return song->tag != NULL; } char * -- cgit v1.2.3