libsaria: Remove DataState optimization

It made sense at the time, but I'm not convinced the added complexity is
actually worth it.

Signed-off-by: Bryan Schumaker <bjschuma@gmail.com>
This commit is contained in:
Bryan Schumaker 2012-11-22 11:13:55 -05:00 committed by Anna Schumaker
parent b7a21789b6
commit 8f7a610d6d
15 changed files with 9 additions and 39 deletions

View File

@ -5,11 +5,6 @@
#include <string>
using namespace std;
enum DataState {
DIRTY,
CLEAN,
};
namespace libsaria
{
bool exists(const string &);
@ -25,7 +20,7 @@ namespace libsaria
void mkdir(const string &);
void rm(const string &);
void save(string, void (*)(ofstream &, void *), DataState *, void *);
void save(string, void (*)(ofstream &, void *), void *);
void read(string, void (*)(ifstream &));
void read_now(string, void (*)(ifstream &));

View File

@ -17,7 +17,6 @@ namespace libsaria
struct Path {
bool visible;
DataState data_state;
unsigned int id;
unsigned int next_track;
string path;

View File

@ -30,7 +30,6 @@ namespace libsaria
private:
int number;
unsigned int flags;
DataState data_state;
unsigned int cur;
vector<Track *> plist;

View File

@ -31,10 +31,9 @@ class WriteTask : public IdleTask
private:
string filepath;
void (*func)(ofstream &, void *);
DataState *state;
void *data;
public:
WriteTask(string, void (*)(ofstream &, void *), DataState *, void *);
WriteTask(string, void (*)(ofstream &, void *), void *);
~WriteTask();
bool should_cancel(void *);
void run_task();

View File

@ -122,10 +122,9 @@ namespace libsaria
make_dir(appdir.c_str());
}
void app::save(string file, void (*func)(ofstream &, void *),
DataState *state, void *data)
void app::save(string file, void (*func)(ofstream &, void *), void *data)
{
new WriteTask(appdir + "/" + file, func, state, data);
new WriteTask(appdir + "/" + file, func, data);
}
void app::read(string file, void (*func)(ifstream &))

View File

@ -4,12 +4,10 @@
#include <fstream>
using namespace std;
WriteTask::WriteTask(string file, void (*fn)(ofstream &, void *),
DataState *s, void *d)
WriteTask::WriteTask(string file, void (*fn)(ofstream &, void *), void *d)
{
filepath = file;
func = fn;
state = s;
data = d;
queue();
@ -21,8 +19,6 @@ WriteTask::~WriteTask()
void WriteTask::run_task()
{
if (*state == CLEAN)
return;
ofstream stream;
stream.open(filepath.c_str());
func(stream, data);

View File

@ -46,7 +46,7 @@ static void do_save_path(ofstream &stream, void *data)
void libsaria::library::save_path(libsaria::library::Path *path)
{
string filepath = libdir + "/" + id_to_filename(path->id);
libsaria::app::save(filepath, do_save_path, &path->data_state, path);
libsaria::app::save(filepath, do_save_path, path);
}
void read_path(ifstream &stream)
@ -76,7 +76,6 @@ void read_path(ifstream &stream)
s >> path.visible;
s >> path.next_track;
s >> size;
path.data_state = CLEAN;
path_ptr = push_path(path);
for (unsigned int i = 0; i < size; i++) {
@ -88,10 +87,8 @@ void read_path(ifstream &stream)
tracks.push_back(track);
}
if (version != 2) {
path_ptr->data_state = DIRTY;
if (version != 2)
libsaria::library::save_path(path_ptr);
}
libsaria::notify(PATH_UPDATED, path_ptr);
if (path.visible) {

View File

@ -96,7 +96,6 @@ namespace libsaria
struct Path path, *path_ptr;
path.visible = true;
path.data_state = CLEAN;
path.id = next_id++;
path.next_track = 0;
path.path = dir;
@ -132,7 +131,6 @@ namespace libsaria
{
path->tracks.for_each_item(hide_track, NULL);
path->visible = false;
path->data_state = DIRTY;
save_path(path);
notify(PATH_UPDATED, path);
}
@ -146,7 +144,6 @@ namespace libsaria
ban::get_banned_plist()->push_back(sort.banned);
path->visible = true;
path->data_state = DIRTY;
save_path(path);
notify(PATH_UPDATED, path);
}

View File

@ -45,7 +45,6 @@ void ValidateTask::run_task()
println("Reaping: " + (*track)[TRACK_FILEPATH]);
lib_playlist.remove_track(&it->get_value());
it = path->tracks.erase(it);
path->data_state = DIRTY;
}
};
@ -112,7 +111,6 @@ void ScanTask::run_task()
try {
li = path->tracks.push_back(libsaria::Track(*it, path));
lib_playlist.push_back(&li->get_value());
path->data_state = DIRTY;
} catch (string message) {
println(message);
}

View File

@ -33,7 +33,6 @@ namespace libsaria
libsaria::deck::init();
app::open_pipe();
}
void quit()

View File

@ -19,7 +19,6 @@ namespace libsaria
{
track->add_playlist(this);
notify_ui(PLAYLIST_ADD, track, ins_index);
data_state = DIRTY;
schedule_save();
if (plist.size() == 1)
cur = 0;
@ -38,7 +37,6 @@ namespace libsaria
if (cur >= plist.size())
cur = 0;
notify_ui(PLAYLIST_RM, track, rm_index);
data_state = DIRTY;
schedule_save();
}

View File

@ -104,7 +104,7 @@ namespace libsaria
}
filepath = plistdir + "/" + number_to_filename(number);
app::save(filepath, save_playlist, &data_state, this);
app::save(filepath, save_playlist, this);
}
void Playlist::rm_file()

View File

@ -8,7 +8,6 @@
#include <stdlib.h>
using namespace std;
static DataState state = CLEAN;
static map<string, int> preferences;
static void save(ofstream &stream, void *data)
@ -20,7 +19,6 @@ static void save(ofstream &stream, void *data)
stream << it->first << endl;
stream << it->second << endl;
}
state = CLEAN;
}
static void load(ifstream &stream)
@ -45,8 +43,7 @@ static void load(ifstream &stream)
static void set_preference(const string &key, int p)
{
preferences[key] = p;
state = DIRTY;
libsaria::app::save("prefs", save, &state, NULL);
libsaria::app::save("prefs", save, NULL);
}
static bool key_exists(const string &key)
@ -61,7 +58,6 @@ namespace libsaria
void prefs::init()
{
libsaria::app::read_now("prefs", load);
state = CLEAN;
}
int prefs::get(const string &key)

View File

@ -9,7 +9,6 @@ namespace libsaria
void Track::set_banned(bool state)
{
banned = state;
path->data_state = DIRTY;
libsaria::library::save_path(path);
if (state)

View File

@ -164,7 +164,6 @@ namespace libsaria
last_month = ltm->tm_mon + 1;
last_year = 1900 + ltm->tm_year;
path->data_state = DIRTY;
library::save_path(path);
for (it = playlists.begin(); it != playlists.end(); it++)