Eliminate history_collection_t

This was a pretty useless type.
This commit is contained in:
ridiculousfish 2019-04-28 15:33:39 -07:00
parent 3d63a68dd0
commit 6e143bf50f

View file

@ -210,16 +210,6 @@ class history_lru_cache_t : public lru_cache_t<history_lru_cache_t, history_lru_
} }
}; };
// The set of histories
// Note that histories are currently immortal
class history_collection_t {
owning_lock<std::map<wcstring, std::unique_ptr<history_t>>> histories;
public:
history_t &get_creating(const wcstring &name);
void save();
};
} // anonymous namespace } // anonymous namespace
// history_file_contents_t holds the read-only contents of a file. // history_file_contents_t holds the read-only contents of a file.
@ -332,7 +322,8 @@ class history_file_contents_t {
} }
}; };
static history_collection_t histories; /// The set of all histories.
static owning_lock<std::map<wcstring, std::unique_ptr<history_t>>> s_histories;
static wcstring history_filename(const wcstring &name, const wcstring &suffix); static wcstring history_filename(const wcstring &name, const wcstring &suffix);
@ -816,11 +807,11 @@ static size_t offset_of_next_item(const history_file_contents_t &contents, size_
return size_t(-1); return size_t(-1);
} }
history_t &history_collection_t::get_creating(const wcstring &name) { history_t &history_t::history_with_name(const wcstring &name) {
// Return a history for the given name, creating it if necessary // Return a history for the given name, creating it if necessary
// Note that histories are currently never deleted, so we can return a reference to them without // Note that histories are currently never deleted, so we can return a reference to them without
// using something like shared_ptr // using something like shared_ptr
auto hs = histories.acquire(); auto hs = s_histories.acquire();
std::unique_ptr<history_t> &hist = (*hs)[name]; std::unique_ptr<history_t> &hist = (*hs)[name];
if (!hist) { if (!hist) {
hist = make_unique<history_t>(name); hist = make_unique<history_t>(name);
@ -828,10 +819,6 @@ history_t &history_collection_t::get_creating(const wcstring &name) {
return *hist; return *hist;
} }
history_t &history_t::history_with_name(const wcstring &name) {
return histories.get_creating(name);
}
history_t::history_t(wcstring pname) history_t::history_t(wcstring pname)
: name(std::move(pname)), history_file_id(kInvalidFileID), boundary_timestamp(time(NULL)) {} : name(std::move(pname)), history_file_id(kInvalidFileID), boundary_timestamp(time(NULL)) {}
@ -1850,16 +1837,13 @@ void history_t::incorporate_external_changes() {
} }
} }
void history_collection_t::save() { void history_save_all() {
// Save all histories auto histories = s_histories.acquire();
auto hists = histories.acquire(); for (auto &p : *histories) {
for (auto &p : *hists) {
p.second->save(); p.second->save();
} }
} }
void history_save_all() { histories.save(); }
/// Return the prefix for the files to be used for command and read history. /// Return the prefix for the files to be used for command and read history.
wcstring history_session_id(const environment_t &vars) { wcstring history_session_id(const environment_t &vars) {
wcstring result = DFLT_FISH_HISTORY_SESSION_ID; wcstring result = DFLT_FISH_HISTORY_SESSION_ID;