| 14 | StyleAttributesCache::StyleAttributesCache(AttributeIds& attributeIds) : _attributeIds(attributeIds) {} |
| 15 | |
| 16 | size_t StyleAttributesCache::resolveAttributesIndex(const Ref<ValueMap>& attributes) { |
| 17 | auto key = StyleAttributesCacheKey(attributes); |
| 18 | const auto& it = _entriesLookup.find(key); |
| 19 | if (it != _entriesLookup.end()) { |
| 20 | return it->second; |
| 21 | } |
| 22 | |
| 23 | std::vector<CSSStyleDeclaration> declarations; |
| 24 | declarations.reserve(attributes->size()); |
| 25 | for (const auto& it : *attributes) { |
| 26 | auto& decl = declarations.emplace_back(); |
| 27 | decl.attribute.id = _attributeIds.getIdForName(it.first); |
| 28 | decl.attribute.value = it.second; |
| 29 | } |
| 30 | |
| 31 | auto cssAttributes = makeShared<CSSAttributes>(std::move(declarations)); |
| 32 | auto index = _entries.size(); |
| 33 | |
| 34 | _entries.emplace_back(cssAttributes); |
| 35 | _entriesLookup[key] = index; |
| 36 | |
| 37 | return index; |
| 38 | } |
| 39 | |
| 40 | Ref<CSSAttributes> StyleAttributesCache::getAttributesForIndex(size_t index) const { |
| 41 | if (index >= _entries.size()) { |
no test coverage detected