database: Insert through a const reference
This should offer a performance increase since the item to insert will only be copied if it is not already in the database. Signed-off-by: Anna Schumaker <anna@ocarinaproject.net>
This commit is contained in:
parent
d452177f32
commit
cac0aee2e6
32
DESIGN
32
DESIGN
|
@ -203,7 +203,7 @@ Database Entry:
|
|||
|
||||
DatabaseEntry();
|
||||
virtual void ~DatabaseEntry() = 0;
|
||||
virtual const std::string primary_key() = 0;
|
||||
virtual const std::string primary_key() const = 0;
|
||||
|
||||
virtual void write(File &) = 0;
|
||||
virtual void read(File &) = 0;
|
||||
|
@ -213,7 +213,7 @@ Database Entry:
|
|||
DatabaseEntry :: DatabaseEntry():
|
||||
Set id = 0.
|
||||
|
||||
const std::string DatabaseEntry :: primary_key();
|
||||
const std::string DatabaseEntry :: primary_key() const;
|
||||
This function should return a unique string representing this
|
||||
DatabaseEntry instance, which will be used to prevent
|
||||
duplicates in a database. This string is not expected to
|
||||
|
@ -274,7 +274,7 @@ Database:
|
|||
void save();
|
||||
void load();
|
||||
|
||||
T *insert(T);
|
||||
T *insert(const T &);
|
||||
void remove(unsigned int);
|
||||
unsigned int size();
|
||||
unsigned int actual_size();
|
||||
|
@ -308,7 +308,7 @@ Database:
|
|||
void Database :: load();
|
||||
Load the database from disk.
|
||||
|
||||
T *Database :: insert(T item);
|
||||
T *Database :: insert(const T &item);
|
||||
Look up the item in the _keys map.
|
||||
If we find an item with the same key:
|
||||
- Return a pointer to the found item.
|
||||
|
@ -373,7 +373,7 @@ Index:
|
|||
set<unsigned int> values;
|
||||
|
||||
IndexEntry(const std::string &);
|
||||
const std::string primary_key();
|
||||
const std::string primary_key() const;
|
||||
void insert(unsigned int);
|
||||
void remove(unsigned int);
|
||||
|
||||
|
@ -388,7 +388,7 @@ Index:
|
|||
IndexEntry :: IndexEntry();
|
||||
Creat an empty IndexEntry.
|
||||
|
||||
std::string IndexEntry :: primary_key();
|
||||
std::string IndexEntry :: primary_key() const;
|
||||
return key;
|
||||
|
||||
void IndexEntry :: insert(unsigned int value);
|
||||
|
@ -609,7 +609,7 @@ Artist Tag:
|
|||
|
||||
Artist();
|
||||
Artist(const std::string &);
|
||||
const std::string primary_key();
|
||||
const std::string primary_key() const;
|
||||
void read(File &);
|
||||
void write(File &);
|
||||
};
|
||||
|
@ -624,7 +624,7 @@ Artist Tag:
|
|||
Artist(const std::string &artist_name);
|
||||
Set artist_name and find the lowercase form.
|
||||
|
||||
const std::string Artist :: primary_key();
|
||||
const std::string Artist :: primary_key() const;
|
||||
Use artist name as primary key.
|
||||
|
||||
void Artist :: read(File &f);
|
||||
|
@ -647,7 +647,7 @@ Album Tag:
|
|||
|
||||
Album();
|
||||
Album(const std::string &, unsigned int);
|
||||
const std::string primary_key();
|
||||
const std::string primary_key() const;
|
||||
void read(File &);
|
||||
void write(File &);
|
||||
};
|
||||
|
@ -663,7 +663,7 @@ Album Tag:
|
|||
Set name and year from album name and album_year. Find the
|
||||
lowercase form of the album name.
|
||||
|
||||
const std::string Album :: primary_key();
|
||||
const std::string Album :: primary_key() const;
|
||||
Return the string: "$year.$name"
|
||||
|
||||
void Album :: read(File &f);
|
||||
|
@ -687,7 +687,7 @@ Genre Tag:
|
|||
|
||||
Genre();
|
||||
Genre(const std::string &);
|
||||
const std::string primary_key();
|
||||
const std::string primary_key() const;
|
||||
void read(File &);
|
||||
void write(File &);
|
||||
};
|
||||
|
@ -702,7 +702,7 @@ Genre Tag:
|
|||
Genre(const std::string &genre_name);
|
||||
Set genre from genre name and find the lowercase form.
|
||||
|
||||
const std::string Genre :: primary_key();
|
||||
const std::string Genre :: primary_key() const;
|
||||
Use genre as primary key.
|
||||
|
||||
void Genre :: read(File &f);
|
||||
|
@ -728,7 +728,7 @@ Library Tag:
|
|||
|
||||
Library();
|
||||
Library(const std::string &);
|
||||
const std::string primary_key();
|
||||
const std::string primary_key() const;
|
||||
void read(File &);
|
||||
void write(File &);
|
||||
};
|
||||
|
@ -747,7 +747,7 @@ Library Tag:
|
|||
Set count = 0.
|
||||
Set enabled = true.
|
||||
|
||||
const std::string Library :: primary_key();
|
||||
const std::string Library :: primary_key() const;
|
||||
Use root_path as the primary key,
|
||||
|
||||
void read(File &f);
|
||||
|
@ -797,7 +797,7 @@ Track Tag:
|
|||
|
||||
Track();
|
||||
Track(const std::string &, Library *);
|
||||
const std::string primary_key();
|
||||
const std::string primary_key() const;
|
||||
void read(File &);
|
||||
void write(File &);
|
||||
|
||||
|
@ -824,7 +824,7 @@ Track Tag:
|
|||
the result to set filepath.
|
||||
- Set library = lib.
|
||||
|
||||
const std::string Track :: primary_key();
|
||||
const std::string Track :: primary_key() const;
|
||||
return path();
|
||||
|
||||
void read(File &f);
|
||||
|
|
|
@ -17,7 +17,7 @@ public:
|
|||
|
||||
DatabaseEntry();
|
||||
virtual ~DatabaseEntry() = 0;
|
||||
virtual const std::string primary_key() = 0;
|
||||
virtual const std::string primary_key() const = 0;
|
||||
virtual void write(File &) = 0;
|
||||
virtual void read(File &) = 0;
|
||||
};
|
||||
|
@ -43,7 +43,7 @@ public:
|
|||
void autosave();
|
||||
void load();
|
||||
|
||||
T *insert(T);
|
||||
T *insert(const T &);
|
||||
void remove(unsigned int);
|
||||
unsigned int size();
|
||||
unsigned int actual_size();
|
||||
|
|
|
@ -80,7 +80,7 @@ void Database<T> :: load()
|
|||
}
|
||||
|
||||
template <class T>
|
||||
T *Database<T> :: insert(T val)
|
||||
T *Database<T> :: insert(const T &val)
|
||||
{
|
||||
T *t = find(val.primary_key());
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ public:
|
|||
|
||||
IndexEntry();
|
||||
IndexEntry(const std::string &);
|
||||
const std::string primary_key();
|
||||
const std::string primary_key() const;
|
||||
void insert(unsigned int);
|
||||
void remove(unsigned int);
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ namespace library
|
|||
AGInfo();
|
||||
AGInfo(DB_Type, TagLib :: Tag *);
|
||||
AGInfo(DB_Type, const std::string &);
|
||||
const std::string primary_key();
|
||||
const std::string primary_key() const;
|
||||
void read(File &);
|
||||
void write(File &);
|
||||
};
|
||||
|
@ -48,7 +48,7 @@ namespace library
|
|||
Album();
|
||||
Album(TagLib :: Tag *, unsigned int);
|
||||
Album(const std::string &, unsigned int, unsigned int);
|
||||
const std::string primary_key();
|
||||
const std::string primary_key() const;
|
||||
void read(File &);
|
||||
void write(File &);
|
||||
};
|
||||
|
@ -62,7 +62,7 @@ namespace library
|
|||
|
||||
Library();
|
||||
Library(const std::string &, bool);
|
||||
const std::string primary_key();
|
||||
const std::string primary_key() const;
|
||||
void read(File &);
|
||||
void write(File &);
|
||||
};
|
||||
|
@ -94,7 +94,7 @@ namespace library
|
|||
unsigned int, const std :: string &);
|
||||
Track(ImportData *, unsigned int, unsigned int,
|
||||
unsigned int, unsigned int);
|
||||
const std::string primary_key();
|
||||
const std::string primary_key() const;
|
||||
void read(File &);
|
||||
void write(File &);
|
||||
};
|
||||
|
|
|
@ -27,7 +27,7 @@ public:
|
|||
|
||||
Artist();
|
||||
Artist(const std::string &);
|
||||
const std::string primary_key();
|
||||
const std::string primary_key() const;
|
||||
void read(File &);
|
||||
void write(File &);
|
||||
};
|
||||
|
@ -41,7 +41,7 @@ public:
|
|||
|
||||
Album();
|
||||
Album(const std::string &, unsigned int);
|
||||
const std::string primary_key();
|
||||
const std::string primary_key() const;
|
||||
void read(File &);
|
||||
void write(File &);
|
||||
};
|
||||
|
@ -54,7 +54,7 @@ public:
|
|||
|
||||
Genre();
|
||||
Genre(const std::string &);
|
||||
const std::string primary_key();
|
||||
const std::string primary_key() const;
|
||||
void read(File &);
|
||||
void write(File &);
|
||||
};
|
||||
|
@ -68,7 +68,7 @@ public:
|
|||
|
||||
Library();
|
||||
Library(const std::string &);
|
||||
const std::string primary_key();
|
||||
const std::string primary_key() const;
|
||||
void read(File &);
|
||||
void write(File &);
|
||||
};
|
||||
|
@ -95,12 +95,12 @@ public:
|
|||
|
||||
Track();
|
||||
Track(const std::string &, Library *);
|
||||
const std::string primary_key();
|
||||
const std::string primary_key() const;
|
||||
void read(File &);
|
||||
void write(File &);
|
||||
|
||||
void tag();
|
||||
const std::string path();
|
||||
const std::string path() const;
|
||||
bool less_than(Track *, sort_t);
|
||||
};
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ IndexEntry :: IndexEntry(const std::string &k)
|
|||
: key(k)
|
||||
{}
|
||||
|
||||
const std::string IndexEntry :: primary_key()
|
||||
const std::string IndexEntry :: primary_key() const
|
||||
{
|
||||
return key;
|
||||
}
|
||||
|
|
|
@ -60,7 +60,7 @@ library :: AGInfo :: AGInfo(DB_Type type, const std::string &str)
|
|||
throw -E_INVAL;
|
||||
}
|
||||
|
||||
const std::string library :: AGInfo :: primary_key()
|
||||
const std::string library :: AGInfo :: primary_key() const
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
@ -100,7 +100,7 @@ library :: Album :: Album(const std::string &str, unsigned int yr, unsigned int
|
|||
name_lower = filter :: lowercase(name);
|
||||
}
|
||||
|
||||
const std::string library :: Album :: primary_key()
|
||||
const std::string library :: Album :: primary_key() const
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << name << "." << year;
|
||||
|
@ -135,7 +135,7 @@ library :: Library :: Library(const std::string &path, bool is_enabled)
|
|||
{
|
||||
}
|
||||
|
||||
const std::string library :: Library :: primary_key()
|
||||
const std::string library :: Library :: primary_key() const
|
||||
{
|
||||
return root_path;
|
||||
}
|
||||
|
@ -211,7 +211,7 @@ library :: Track :: Track(struct ImportData *data, unsigned int lib,
|
|||
length_str = ss.str();
|
||||
}
|
||||
|
||||
const std::string library :: Track :: primary_key()
|
||||
const std::string library :: Track :: primary_key() const
|
||||
{
|
||||
return full_path;
|
||||
}
|
||||
|
|
12
lib/tags.cpp
12
lib/tags.cpp
|
@ -28,7 +28,7 @@ Artist :: Artist(const std::string &s)
|
|||
{
|
||||
}
|
||||
|
||||
const std::string Artist :: primary_key()
|
||||
const std::string Artist :: primary_key() const
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
@ -59,7 +59,7 @@ Album :: Album(const std::string &s, unsigned int y)
|
|||
{
|
||||
}
|
||||
|
||||
const std::string Album :: primary_key()
|
||||
const std::string Album :: primary_key() const
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << year << "." << name;
|
||||
|
@ -93,7 +93,7 @@ Genre :: Genre(const std::string &s)
|
|||
{
|
||||
}
|
||||
|
||||
const std::string Genre :: primary_key()
|
||||
const std::string Genre :: primary_key() const
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
@ -127,7 +127,7 @@ Library :: Library(const std::string &s)
|
|||
{
|
||||
}
|
||||
|
||||
const std::string Library :: primary_key()
|
||||
const std::string Library :: primary_key() const
|
||||
{
|
||||
return root_path;
|
||||
}
|
||||
|
@ -159,7 +159,7 @@ Track :: Track(const std::string &f, Library *l)
|
|||
{
|
||||
}
|
||||
|
||||
const std::string Track :: primary_key()
|
||||
const std::string Track :: primary_key() const
|
||||
{
|
||||
return path();
|
||||
}
|
||||
|
@ -176,7 +176,7 @@ void Track :: tag()
|
|||
{
|
||||
}
|
||||
|
||||
const std::string Track :: path()
|
||||
const std::string Track :: path() const
|
||||
{
|
||||
return library->root_path + "/" + filepath;
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ public:
|
|||
|
||||
IntEntry();
|
||||
IntEntry(unsigned int);
|
||||
const std::string primary_key();
|
||||
const std::string primary_key() const;
|
||||
void write(File &);
|
||||
void read(File &);
|
||||
void print();
|
||||
|
@ -28,7 +28,7 @@ public:
|
|||
|
||||
IntEntry :: IntEntry() : val(0) {}
|
||||
IntEntry :: IntEntry(unsigned int v) : val(v) {}
|
||||
const std::string IntEntry :: primary_key()
|
||||
const std::string IntEntry :: primary_key() const
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << val;
|
||||
|
|
|
@ -19,7 +19,7 @@ public:
|
|||
std::string key;
|
||||
|
||||
IntEntry(unsigned int, const std::string &);
|
||||
const std::string primary_key();
|
||||
const std::string primary_key() const;
|
||||
void write(File &);
|
||||
void read(File &);
|
||||
void print();
|
||||
|
@ -31,7 +31,7 @@ IntEntry :: IntEntry(unsigned int i, const std::string &s)
|
|||
key = s;
|
||||
}
|
||||
|
||||
const std::string IntEntry :: primary_key()
|
||||
const std::string IntEntry :: primary_key() const
|
||||
{
|
||||
return key;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue