Skip to content

Commit

Permalink
Implement extend memoize on the compound selector level
Browse files Browse the repository at this point in the history
We obviously need to return clones from the function.
  • Loading branch information
mgreter committed Feb 4, 2017
1 parent c02a2a5 commit 455a103
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/extend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1511,6 +1511,13 @@ namespace Sass {
};
Node Extend::extendCompoundSelector(Compound_Selector_Ptr pSelector, CompoundSelectorSet& seen, bool isReplace) {

// check if we already extended this selector
// we can do this since subset_map is "static"
auto memoized = memoizeCompound.find(pSelector);
if (memoized != memoizeCompound.end()) {
return memoized->second.klone();
}

DEBUG_EXEC(EXTEND_COMPOUND, printCompoundSelector(pSelector, "EXTEND COMPOUND: "))
// TODO: Ruby has another loop here to skip certain members?

Expand Down Expand Up @@ -1658,6 +1665,9 @@ namespace Sass {

DEBUG_EXEC(EXTEND_COMPOUND, printCompoundSelector(pSelector, "EXTEND COMPOUND END: "))

// memory results in a map table - since extending is very expensive
memoizeCompound.insert(std::pair<Compound_Selector_Obj, Node>(pSelector, results));

return results;
}

Expand Down
7 changes: 7 additions & 0 deletions src/extend.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ namespace Sass {
CompareNodes // compare
> memoizeComplex;

std::unordered_map<
Compound_Selector_Obj, // key
Node, // value
HashNodes, // hasher
CompareNodes // compare
> memoizeCompound;

void extendObjectWithSelectorAndBlock(Ruleset_Ptr pObject);
Node extendComplexSelector(Complex_Selector_Ptr sel, CompoundSelectorSet& seen, bool isReplace, bool isOriginal);
Node extendCompoundSelector(Compound_Selector_Ptr sel, CompoundSelectorSet& seen, bool isReplace);
Expand Down

0 comments on commit 455a103

Please sign in to comment.