MCPcopy Create free account
hub / github.com/Snapchat/Valdi / resolveAttributesIndex

Method resolveAttributesIndex

valdi/src/valdi/runtime/CSS/StyleAttributesCache.cpp:16–38  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

14StyleAttributesCache::StyleAttributesCache(AttributeIds& attributeIds) : _attributeIds(attributeIds) {}
15
16size_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
40Ref<CSSAttributes> StyleAttributesCache::getAttributesForIndex(size_t index) const {
41 if (index >= _entries.size()) {

Callers 1

runtimeCreateCSSRuleMethod · 0.80

Calls 6

getIdForNameMethod · 0.80
endMethod · 0.65
findMethod · 0.45
reserveMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected