diff --git a/src/history.cpp b/src/history.cpp index dcc041c97..12ef8b14f 100644 --- a/src/history.cpp +++ b/src/history.cpp @@ -210,16 +210,6 @@ class history_lru_cache_t : public lru_cache_t>> histories; - - public: - history_t &get_creating(const wcstring &name); - void save(); -}; - } // anonymous namespace // 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>> s_histories; 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); } -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 // Note that histories are currently never deleted, so we can return a reference to them without // using something like shared_ptr - auto hs = histories.acquire(); + auto hs = s_histories.acquire(); std::unique_ptr &hist = (*hs)[name]; if (!hist) { hist = make_unique(name); @@ -828,10 +819,6 @@ history_t &history_collection_t::get_creating(const wcstring &name) { return *hist; } -history_t &history_t::history_with_name(const wcstring &name) { - return histories.get_creating(name); -} - history_t::history_t(wcstring pname) : 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() { - // Save all histories - auto hists = histories.acquire(); - for (auto &p : *hists) { +void history_save_all() { + auto histories = s_histories.acquire(); + for (auto &p : *histories) { p.second->save(); } } -void history_save_all() { histories.save(); } - /// Return the prefix for the files to be used for command and read history. wcstring history_session_id(const environment_t &vars) { wcstring result = DFLT_FISH_HISTORY_SESSION_ID;