summaryrefslogtreecommitdiff
path: root/src/audiocachefile.cc
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2016-01-30 10:56:11 +0100
committerBent Bisballe Nyeng <deva@aasimon.org>2016-01-30 10:56:11 +0100
commitac1d5566d30b107fdea934ac704720242ef59a7c (patch)
treeed46cdc2ebc66612ade9bbac5f41097698cef042 /src/audiocachefile.cc
parentaa635eb8da9804488513d1f3d422e4810e611bb8 (diff)
parent22715c84cc861ba6ce7e9caa5d214bb3f006679d (diff)
Merge branch 'diskstreaming_review_chaot' into diskstreaming
Diffstat (limited to 'src/audiocachefile.cc')
-rw-r--r--src/audiocachefile.cc26
1 files changed, 10 insertions, 16 deletions
diff --git a/src/audiocachefile.cc b/src/audiocachefile.cc
index 91fcecf..7b05bfc 100644
--- a/src/audiocachefile.cc
+++ b/src/audiocachefile.cc
@@ -130,25 +130,20 @@ AudioCacheFile& AudioCacheFiles::getFile(const std::string& filename)
{
std::lock_guard<std::mutex> lock(mutex);
- AudioCacheFile* cache_audio_file = nullptr;
-
auto it = audiofiles.find(filename);
if(it == audiofiles.end())
{
- cache_audio_file = new AudioCacheFile(filename, read_buffer);
- audiofiles.insert(std::make_pair(filename, cache_audio_file));
- }
- else
- {
- cache_audio_file = it->second;
+ // Construct a new AudioCacheFile in place. The in place construction is relevant.
+ it = audiofiles.emplace(std::piecewise_construct, std::make_tuple(filename),
+ std::make_tuple(filename, std::ref(read_buffer))).first;
}
- assert(cache_audio_file);
+ auto& cache_audio_file = it->second;
// Increase ref count.
- ++cache_audio_file->ref;
+ ++cache_audio_file.ref;
- return *cache_audio_file;
+ return cache_audio_file;
}
void AudioCacheFiles::releaseFile(const std::string& filename)
@@ -162,14 +157,13 @@ void AudioCacheFiles::releaseFile(const std::string& filename)
return; // not open
}
- auto audiofile = it->second;
+ auto& audiofile = it->second;
- assert(audiofile->ref); // If ref is not > 0 it shouldn't be in the map.
+ assert(audiofile.ref); // If ref is not > 0 it shouldn't be in the map.
- --audiofile->ref;
- if(audiofile->ref == 0)
+ --audiofile.ref;
+ if(audiofile.ref == 0)
{
- delete audiofile;
audiofiles.erase(it);
}
}