Commit 39af0c0b authored by Scott Wheeler's avatar Scott Wheeler

A bunch of optimizations that seem to cut a sigificant amount off of the

startup time.

svn path=/trunk/kdemultimedia/juk/; revision=203677
parent 32e59c13
......@@ -3,12 +3,12 @@ bin_PROGRAMS = juk
## INCLUDES were found outside kdevelop specific part
juk_SOURCES = systemtray.cpp genrelisteditor.cpp genrelisteditorbase.ui splashscreen.cpp statuslabel.cpp cachedtag.cpp oggtag.cpp id3tag.cpp collectionlist.cpp playlistitem.cpp playlist.cpp playlistsplitter.cpp listboxpixmap.cpp playlistbox.cpp tageditor.cpp cache.cpp audiodata.cpp genrelistreader.cpp genrelistlist.cpp genrelist.cpp genre.cpp player.cpp tag.cpp customaction.cpp slideraction.cpp juk.cpp main.cpp
juk_SOURCES = sortedstringlist.cpp systemtray.cpp genrelisteditor.cpp genrelisteditorbase.ui splashscreen.cpp statuslabel.cpp cachedtag.cpp oggtag.cpp id3tag.cpp collectionlist.cpp playlistitem.cpp playlist.cpp playlistsplitter.cpp listboxpixmap.cpp playlistbox.cpp tageditor.cpp cache.cpp audiodata.cpp genrelistreader.cpp genrelistlist.cpp genrelist.cpp genre.cpp player.cpp tag.cpp customaction.cpp slideraction.cpp juk.cpp main.cpp
juk_LDADD = -lid3 -lsoundserver_idl $(LIB_KFILE) $(LIB_KDEUI) $(LIB_KDECORE) $(LIB_QT) $(LIBSOCKET)
SUBDIRS = pics data
EXTRA_DIST = main.cpp juk.cpp juk.h juk.desktop jukui.rc slideraction.cpp slideraction.h customaction.h customaction.cpp tag.cpp tag.h player.cpp player.h genre.h genre.cpp hi16-app-juk.png hi32-app-juk.png hi48-app-juk.png genrelist.cpp genrelist.h genrelistlist.cpp genrelistlist.h genrelistreader.cpp genrelistreader.h audiodata.cpp audiodata.h cache.cpp cache.h tageditor.cpp tageditor.h playlistbox.cpp playlistbox.h listboxpixmap.cpp listboxpixmap.h playlistsplitter.cpp playlistsplitter.h playlist.cpp playlist.h playlistitem.cpp playlistitem.h collectionlist.cpp collectionlist.h id3tag.cpp id3tag.h oggtag.cpp oggtag.h cachedtag.cpp cachedtag.h statuslabel.cpp statuslabel.h splashscreen.cpp splashscreen.h genrelisteditorbase.ui genrelisteditor.cpp genrelisteditor.h systemtray.h systemtray.cpp
EXTRA_DIST = main.cpp juk.cpp juk.h juk.desktop jukui.rc slideraction.cpp slideraction.h customaction.h customaction.cpp tag.cpp tag.h player.cpp player.h genre.h genre.cpp hi16-app-juk.png hi32-app-juk.png hi48-app-juk.png genrelist.cpp genrelist.h genrelistlist.cpp genrelistlist.h genrelistreader.cpp genrelistreader.h audiodata.cpp audiodata.h cache.cpp cache.h tageditor.cpp tageditor.h playlistbox.cpp playlistbox.h listboxpixmap.cpp listboxpixmap.h playlistsplitter.cpp playlistsplitter.h playlist.cpp playlist.h playlistitem.cpp playlistitem.h collectionlist.cpp collectionlist.h id3tag.cpp id3tag.h oggtag.cpp oggtag.h cachedtag.cpp cachedtag.h statuslabel.cpp statuslabel.h splashscreen.cpp splashscreen.h genrelisteditorbase.ui genrelisteditor.cpp genrelisteditor.h systemtray.h systemtray.cpp sortedstringlist.cpp sortedstringlist.h
install-data-local:
$(mkinstalldirs) $(kde_appsdir)/Multimedia/
......
......@@ -42,7 +42,7 @@ void CollectionList::initialize(PlaylistSplitter *s, QWidget *parent, bool resto
if(restoreOnLoad)
for(QDictIterator<Tag>it(*Cache::instance()); it.current(); ++it)
new CollectionListItem(it.current()->fileInfo());
new CollectionListItem(it.current()->fileInfo(), it.current()->absFilePath());
}
////////////////////////////////////////////////////////////////////////////////
......@@ -51,12 +51,12 @@ void CollectionList::initialize(PlaylistSplitter *s, QWidget *parent, bool resto
QStringList CollectionList::artists() const
{
return(artistList);
return(artistList.values());
}
QStringList CollectionList::albums() const
{
return(albumList);
return(albumList.values());
}
CollectionListItem *CollectionList::lookup(const QString &file)
......@@ -66,10 +66,11 @@ CollectionListItem *CollectionList::lookup(const QString &file)
PlaylistItem *CollectionList::createItem(const QFileInfo &file, QListViewItem *)
{
if(itemsDict.find(file.absFilePath()))
QString path = file.absFilePath();
if(itemsDict.find(path))
return(0);
return(new CollectionListItem(file));
return(new CollectionListItem(file, path));
}
////////////////////////////////////////////////////////////////////////////////
......@@ -124,26 +125,32 @@ void CollectionList::removeFromDict(const QString &file)
void CollectionList::addArtist(const QString &artist)
{
if(artistList.contains(artist) == 0)
artistList.append(artist);
// Do a bit of caching since there will very often be "two in a row" insertions.
static QString previousArtist;
if(artist != previousArtist && !artistList.insert(artist))
previousArtist = artist;
}
void CollectionList::addAlbum(const QString &album)
{
if(albumList.contains(album) == 0)
albumList.append(album);
// Do a bit of caching since there will very often be "two in a row" insertions.
static QString previousAlbum;
if(album != previousAlbum && !albumList.insert(album))
previousAlbum = album;
}
////////////////////////////////////////////////////////////////////////////////
// CollectionListItem public methods
////////////////////////////////////////////////////////////////////////////////
CollectionListItem::CollectionListItem(const QFileInfo &file) : PlaylistItem(CollectionList::instance())
CollectionListItem::CollectionListItem(const QFileInfo &file, const QString &path) : PlaylistItem(CollectionList::instance())
{
CollectionList *l = CollectionList::instance();
if(l) {
l->addToDict(file.absFilePath(), this);
setData(Data::newUser(file));
l->addToDict(path, this);
setData(Data::newUser(file, path));
refresh();
connect(this, SIGNAL(refreshed()), l, SIGNAL(dataChanged()));
}
......
......@@ -22,6 +22,7 @@
#include "playlist.h"
#include "playlistitem.h"
#include "sortedstringlist.h"
/**
* This is the "collection", or all of the music files that have been opened
......@@ -79,8 +80,8 @@ protected:
private:
static CollectionList *list;
QDict<CollectionListItem> itemsDict;
QStringList artistList;
QStringList albumList;
SortedStringList artistList;
SortedStringList albumList;
};
class CollectionListItem : public PlaylistItem
......@@ -98,7 +99,7 @@ public slots:
virtual void refresh();
protected:
CollectionListItem(const QFileInfo &file);
CollectionListItem(const QFileInfo &file, const QString &path);
void addChildItem(PlaylistItem *child);
};
......
......@@ -156,7 +156,7 @@ void Playlist::saveAs()
internalFile = false;
if(playlistFileName != QString::null) {
if(!splitter->playlistExtensions().contains(playlistFileName.section('.', -1)))
if(splitter->playlistExtensions().find(playlistFileName.section('.', -1)) == splitter->playlistExtensions().end())
playlistFileName.append('.' + splitter->playlistExtensions().first());
......@@ -186,7 +186,7 @@ void Playlist::clearItems(const PlaylistItemList &items)
{
QPtrListIterator<PlaylistItem> it(items);
while(it.current()) {
members.remove(it.current()->absFilePath());
// members.remove(it.current()->absFilePath()); // TODO: fix this for the new sorted class
delete(it.current());
++it;
}
......@@ -397,13 +397,14 @@ void Playlist::contentsDragMoveEvent(QDragMoveEvent *e)
PlaylistItem *Playlist::createItem(const QFileInfo &file, QListViewItem *after)
{
CollectionListItem *item = CollectionList::instance()->lookup(file.absFilePath());
QString filePath = file.absFilePath();
CollectionListItem *item = CollectionList::instance()->lookup(filePath);
if(!item && CollectionList::instance())
item = new CollectionListItem(file);
item = new CollectionListItem(file, filePath);
if(item && members.contains(file.absFilePath()) == 0 || allowDuplicates) {
members.append(file.absFilePath());
if(item && !members.insert(filePath) || allowDuplicates) {
PlaylistItem *i;
if(after)
i = new PlaylistItem(item, this, after);
......
......@@ -24,6 +24,7 @@
#include <qptrstack.h>
#include "playlistitem.h"
#include "sortedstringlist.h"
class PlaylistSplitter;
class PlaylistBoxItem;
......@@ -178,7 +179,7 @@ private:
QPopupMenu *rmbMenu;
int currentColumn;
QStringList members;
SortedStringList members;
int processed;
bool allowDuplicates;
......
......@@ -216,9 +216,9 @@ int PlaylistItem::compare(const PlaylistItem *firstItem, const PlaylistItem *sec
// PlaylistItem::Data public methods
////////////////////////////////////////////////////////////////////////////////
PlaylistItem::Data *PlaylistItem::Data::newUser(const QFileInfo &file)
PlaylistItem::Data *PlaylistItem::Data::newUser(const QFileInfo &file, const QString &path)
{
return new Data(file);
return new Data(file, path);
}
PlaylistItem::Data *PlaylistItem::Data::newUser()
......@@ -231,6 +231,7 @@ void PlaylistItem::Data::refresh()
{
delete(dataTag);
dataTag = Tag::createTag(filePath());
absFileName = absFilePath();
}
void PlaylistItem::Data::deleteUser()
......@@ -257,10 +258,10 @@ void PlaylistItem::Data::setFile(const QString &file)
// PlaylistItem::Data protected methods
////////////////////////////////////////////////////////////////////////////////
PlaylistItem::Data::Data(const QFileInfo &file) : QFileInfo(file)
PlaylistItem::Data::Data(const QFileInfo &file, const QString &path) : QFileInfo(file), absFileName(path)
{
referenceCount = 1;
dataTag = Tag::createTag(filePath());
dataTag = Tag::createTag(path);
}
PlaylistItem::Data::~Data()
......
......@@ -114,7 +114,7 @@ private:
class PlaylistItem::Data : public QFileInfo
{
public:
static Data *newUser(const QFileInfo &file);
static Data *newUser(const QFileInfo &file, const QString &path);
Data *newUser();
void deleteUser();
......@@ -124,6 +124,8 @@ public:
void setFile(const QString &file);
QString absFilePath() const { return(absFileName); }
protected:
/**
* Because we're trying to use this as a shared item, we want all access
......@@ -132,12 +134,13 @@ protected:
* and deletion should be handled by deleteUser. Making the constructor
* and destructor protected ensures this.
*/
Data(const QFileInfo &file);
Data(const QFileInfo &file, const QString &path);
virtual ~Data();
private:
int referenceCount;
Tag *dataTag;
QString absFileName;
};
#endif
......@@ -295,11 +295,9 @@ void PlaylistSplitter::openPlaylist()
Playlist *PlaylistSplitter::openPlaylist(const QString &playlistFile)
{
QFileInfo file(playlistFile);
if(!file.exists() || !file.isFile() || !file.isReadable() || playlistFiles.contains(file.absFilePath()))
if(!file.exists() || !file.isFile() || !file.isReadable() || playlistFiles.insert(file.absFilePath()))
return(0);
playlistFiles.append(file.absFilePath());
Playlist *p = new Playlist(this, playlistFile, playlistStack, file.baseName(true).latin1());
setupPlaylist(p);
return(p);
......
......@@ -29,6 +29,7 @@
#include "collectionlist.h"
#include "tageditor.h"
#include "playlist.h"
#include "sortedstringlist.h"
class PlaylistBoxItem;
......@@ -275,7 +276,7 @@ private:
CollectionList *collection;
QStringList playlistFiles;
SortedStringList playlistFiles;
QStringList mediaExtensions;
QStringList listExtensions;
......
/***************************************************************************
sortedstringlist.cpp - description
-------------------
begin : Wed Jan 29 2003
copyright : (C) 2003 by Scott Wheeler
email : wheeler@kde.org
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include <kdebug.h>
#include "sortedstringlist.h"
static const int tableSize = 5003;
class SortedStringList::Node
{
public:
Node(const QString &value) : key(value), next(0) {}
~Node() {}
QString key;
Node *next;
};
SortedStringList::SortedStringList() : table(tableSize)
{
}
SortedStringList::~SortedStringList()
{
for(int i = 0; i < tableSize; i++)
deleteNode(table[i]);
}
bool SortedStringList::insert(const QString &value)
{
int h = hash(value);
Node *i = table[h];
Node *j = 0;
while(i) {
if(i->key == value)
return true;
else {
j = i;
i = i->next;
}
}
if(j)
j->next = new Node(value);
else
table.insert(h, new Node(value));
return false;
}
bool SortedStringList::contains(const QString &value) const
{
int h = hash(value);
Node *i = table[h];
while(i && i->key != value)
i = i->next;
return bool(i);
}
QStringList SortedStringList::values() const
{
QStringList l;
Node *n;
for(int i = 0; i < tableSize; i++) {
n = table[i];
while(n) {
l.append(n->key);
n = n->next;
}
}
return l;
}
////////////////////////////////////////////////////////////////////////////////
// private methods
////////////////////////////////////////////////////////////////////////////////
int SortedStringList::hash(const QString &key) const
{
uint h = 0;
uint g;
const QChar *p = key.unicode();
for(int i = 0; i < int(key.length()); i++) {
h = (h << 4) + p[i].cell();
if((g = h & 0xf0000000))
h ^= g >> 24;
h &= ~g;
}
int index = h;
if(index < 0)
index = -index;
return(index % tableSize);
}
void SortedStringList::deleteNode(Node *n)
{
if(n) {
deleteNode(n->next);
delete(n);
}
}
/***************************************************************************
sortedstringlist.h - description
-------------------
begin : Wed Jan 29 2003
copyright : (C) 2003 by Scott Wheeler
email : wheeler@kde.org
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef SORTEDSTRINGLIST_H
#define SORTEDSTRINGLIST_H
#include <qstring.h>
#include <qstringlist.h>
#include <qptrvector.h>
class SortedStringList
{
public:
SortedStringList();
~SortedStringList();
bool insert(const QString &value);
bool contains(const QString &value) const;
/**
* Returns a sorted list of the values.
* Warning, this method is expensive and shouldn't be used except when
* necessary.
*/
QStringList values() const;
private:
class Node;
int hash(const QString &key) const;
void deleteNode(Node *n);
QPtrVector<Node> table;
};
#endif
......@@ -57,10 +57,9 @@ Tag::~Tag()
// protected methods
////////////////////////////////////////////////////////////////////////////////
Tag::Tag(const QString &file)
Tag::Tag(const QString &file) : info(file), fileName(file)
{
info.setFile(file);
Cache::instance()->insert(info.absFilePath(), this);
Cache::instance()->insert(file, this);
}
QString Tag::readBitrate(const KFileMetaInfo &metaInfo)
......
......@@ -75,7 +75,7 @@ public:
// These functions are inlined because they are used on startup -- the most
// performance critical section of JuK.
inline QString absFilePath() const { return(info.absFilePath()); }
inline QString absFilePath() const { return(fileName); }
inline QDateTime lastModified() const { return(info.lastModified()); }
inline bool fileExists() const { return(info.exists() && info.isFile()); }
inline QFileInfo fileInfo() const { return(info); }
......@@ -95,6 +95,7 @@ protected:
private:
QFileInfo info;
QString fileName;
};
QDataStream &operator<<(QDataStream &s, const Tag &t);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment