MCPcopy Create free account
hub / github.com/TypesettingTools/Aegisub / CleanExtradata

Method CleanExtradata

src/ass_file.cpp:274–307  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

272}
273
274void AssFile::CleanExtradata() {
275 if (Extradata.empty()) return;
276
277 std::unordered_set<uint32_t> ids_used;
278 for (auto& line : Events) {
279 if (line.ExtradataIds.get().empty()) continue;
280
281 // Find the ID for each unique key in the line
282 reference_map<std::string, uint32_t> keys_used;
283 enumerate_extradata(Extradata, line.ExtradataIds.get(), [&](ExtradataEntry const& e) {
284 keys_used[e.key] = e.id;
285 });
286
287 for (auto const& used : keys_used)
288 ids_used.insert(used.second);
289
290 // If any keys were duplicated or missing, update the id list
291 if (keys_used.size() != line.ExtradataIds.get().size()) {
292 std::vector<uint32_t> ids;
293 ids.reserve(keys_used.size());
294 for (auto const& used : keys_used)
295 ids.push_back(used.second);
296 std::sort(begin(ids), end(ids));
297 line.ExtradataIds = std::move(ids);
298 }
299 }
300
301 if (ids_used.size() != Extradata.size()) {
302 // Erase all no-longer-used extradata entries
303 Extradata.erase(std::remove_if(begin(Extradata), end(Extradata), [&](ExtradataEntry const& e) {
304 return !ids_used.count(e.id);
305 }), end(Extradata));
306 }
307}

Callers 1

SaveMethod · 0.80

Calls 7

enumerate_extradataFunction · 0.85
beginFunction · 0.85
push_backMethod · 0.80
eraseMethod · 0.80
endFunction · 0.50
getMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected