From 455a103da691779de03bc125a3765a9ea93d7472 Mon Sep 17 00:00:00 2001 From: Marcel Greter Date: Sat, 4 Feb 2017 14:28:12 +0100 Subject: [PATCH] Implement extend memoize on the compound selector level We obviously need to return clones from the function. --- src/extend.cpp | 10 ++++++++++ src/extend.hpp | 7 +++++++ 2 files changed, 17 insertions(+) diff --git a/src/extend.cpp b/src/extend.cpp index 2199e4eb4e..46f5c833aa 100644 --- a/src/extend.cpp +++ b/src/extend.cpp @@ -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? @@ -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(pSelector, results)); + return results; } diff --git a/src/extend.hpp b/src/extend.hpp index 92d4e5bc0f..956a311450 100644 --- a/src/extend.hpp +++ b/src/extend.hpp @@ -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);