| 117 | |
| 118 | template <typename Data> |
| 119 | [[nodiscard]] std::shared_ptr<Streaming::Document> Streaming::sharedDocument( |
| 120 | base::flat_map<not_null<Data*>, std::weak_ptr<Document>> &documents, |
| 121 | base::flat_map<not_null<Data*>, std::weak_ptr<Reader>> &readers, |
| 122 | not_null<Data*> data, |
| 123 | DocumentData *original, |
| 124 | HistoryItem *context, |
| 125 | FileOrigin origin) { |
| 126 | auto otherQualities = LookupOtherQualities(original, data, context); |
| 127 | const auto i = documents.find(data); |
| 128 | if (i != end(documents)) { |
| 129 | if (auto result = i->second.lock()) { |
| 130 | if (!otherQualities.empty()) { |
| 131 | result->setOtherQualities(std::move(otherQualities)); |
| 132 | } |
| 133 | return result; |
| 134 | } |
| 135 | } |
| 136 | auto reader = sharedReader(readers, data, origin); |
| 137 | if (!reader) { |
| 138 | return nullptr; |
| 139 | } |
| 140 | auto result = std::make_shared<Document>( |
| 141 | data, |
| 142 | std::move(reader), |
| 143 | std::move(otherQualities)); |
| 144 | if (!PruneDestroyedAndSet(documents, data, result)) { |
| 145 | documents.emplace_or_assign(data, result); |
| 146 | } |
| 147 | return result; |
| 148 | } |
| 149 | |
| 150 | template <typename Data> |
| 151 | void Streaming::keepAlive( |
no test coverage detected