diff options
author | Max Kellermann <max@duempel.org> | 2013-04-08 22:34:44 +0200 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2013-04-08 23:11:36 +0200 |
commit | 96882175f15230fe2cf9b4e7f3a7f29b5697fe26 (patch) | |
tree | d349c29e72cca8cc56aebd70d3f6f265925232ee /src/StateFile.cxx | |
parent | 484841fc9e1e038a04c5c52cf1d9443fd7e337fa (diff) | |
download | mpd-96882175f15230fe2cf9b4e7f3a7f29b5697fe26.tar.gz mpd-96882175f15230fe2cf9b4e7f3a7f29b5697fe26.tar.xz mpd-96882175f15230fe2cf9b4e7f3a7f29b5697fe26.zip |
StateFile: move code to RememberVersions(), IsModified()
Diffstat (limited to 'src/StateFile.cxx')
-rw-r--r-- | src/StateFile.cxx | 33 |
1 files changed, 21 insertions, 12 deletions
diff --git a/src/StateFile.cxx b/src/StateFile.cxx index a15eb7220..301ae9abb 100644 --- a/src/StateFile.cxx +++ b/src/StateFile.cxx @@ -45,6 +45,24 @@ StateFile::StateFile(Path &&_path, const char *_path_utf8, } void +StateFile::RememberVersions() +{ + prev_volume_version = sw_volume_state_get_hash(); + prev_output_version = audio_output_state_get_version(); + prev_playlist_version = playlist_state_get_hash(&partition.playlist, + &partition.pc); +} + +bool +StateFile::IsModified() const +{ + return prev_volume_version != sw_volume_state_get_hash() || + prev_output_version != audio_output_state_get_version() || + prev_playlist_version != playlist_state_get_hash(&partition.playlist, + &partition.pc); +} + +void StateFile::Write() { g_debug("Saving state file %s", path_utf8.c_str()); @@ -62,10 +80,7 @@ StateFile::Write() fclose(fp); - prev_volume_version = sw_volume_state_get_hash(); - prev_output_version = audio_output_state_get_version(); - prev_playlist_version = playlist_state_get_hash(&partition.playlist, - &partition.pc); + RememberVersions(); } void @@ -92,19 +107,13 @@ StateFile::Read() g_warning("Unrecognized line in state file: %s", line); } - prev_volume_version = sw_volume_state_get_hash(); - prev_output_version = audio_output_state_get_version(); - prev_playlist_version = playlist_state_get_hash(&partition.playlist, - &partition.pc); + RememberVersions(); } inline void StateFile::AutoWrite() { - if (prev_volume_version == sw_volume_state_get_hash() && - prev_output_version == audio_output_state_get_version() && - prev_playlist_version == playlist_state_get_hash(&partition.playlist, - &partition.pc)) + if (!IsModified()) /* nothing has changed - don't save the state file, don't spin up the hard disk */ return; |