Changeset 192935 in webkit for trunk/Source/JavaScriptCore/bytecode/EvalCodeCache.h
- Timestamp:
- Dec 1, 2015, 5:37:19 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/bytecode/EvalCodeCache.h
r192914 r192935 35 35 #include "Options.h" 36 36 #include "SourceCode.h" 37 #include "SourceCodeKey.h"38 37 #include <wtf/HashMap.h> 39 38 #include <wtf/RefPtr.h> … … 46 45 class EvalCodeCache { 47 46 public: 48 EvalExecutable* tryGet(bool inStrictContext, const S ourceCode& evalSource, ThisTDZMode thisTDZMode, JSScope* scope)47 EvalExecutable* tryGet(bool inStrictContext, const String& evalSource, JSScope* scope) 49 48 { 50 if (isCacheable(inStrictContext, evalSource, scope)) { 51 ASSERT(!inStrictContext); 52 SourceCodeKey sourceCodeKey(evalSource, String(), SourceCodeKey::EvalType, JSParserBuiltinMode::NotBuiltin, JSParserStrictMode::NotStrict, thisTDZMode); 53 return m_cacheMap.get(sourceCodeKey).get(); 54 } 55 return nullptr; 49 if (isCacheable(inStrictContext, evalSource, scope)) 50 return m_cacheMap.get(evalSource.impl()).get(); 51 return 0; 56 52 } 57 53 58 EvalExecutable* getSlow(ExecState* exec, JSCell* owner, bool inStrictContext, ThisTDZMode thisTDZMode, const S ourceCode& evalSource, JSScope* scope)54 EvalExecutable* getSlow(ExecState* exec, JSCell* owner, bool inStrictContext, ThisTDZMode thisTDZMode, const String& evalSource, JSScope* scope) 59 55 { 60 56 VariableEnvironment variablesUnderTDZ; 61 57 JSScope::collectVariablesUnderTDZ(scope, variablesUnderTDZ); 62 EvalExecutable* evalExecutable = EvalExecutable::create(exec, evalSource, inStrictContext, thisTDZMode, &variablesUnderTDZ);58 EvalExecutable* evalExecutable = EvalExecutable::create(exec, makeSource(evalSource), inStrictContext, thisTDZMode, &variablesUnderTDZ); 63 59 if (!evalExecutable) 64 return nullptr;60 return 0; 65 61 66 if (isCacheable(inStrictContext, evalSource, scope) && m_cacheMap.size() < maxCacheEntries) { 67 ASSERT(!inStrictContext); 68 SourceCodeKey sourceCodeKey(evalSource, String(), SourceCodeKey::EvalType, JSParserBuiltinMode::NotBuiltin, JSParserStrictMode::NotStrict, thisTDZMode); 69 m_cacheMap.set(sourceCodeKey, WriteBarrier<EvalExecutable>(exec->vm(), owner, evalExecutable)); 70 } 62 if (isCacheable(inStrictContext, evalSource, scope) && m_cacheMap.size() < maxCacheEntries) 63 m_cacheMap.set(evalSource.impl(), WriteBarrier<EvalExecutable>(exec->vm(), owner, evalExecutable)); 71 64 72 65 return evalExecutable; … … 88 81 } 89 82 90 ALWAYS_INLINE bool isCacheable(bool inStrictContext, const S ourceCode& evalSource, JSScope* scope)83 ALWAYS_INLINE bool isCacheable(bool inStrictContext, const String& evalSource, JSScope* scope) 91 84 { 92 85 // If eval() is called and it has access to a lexical scope, we can't soundly cache it. 93 86 // If the eval() only has access to the "var" scope, then we can cache it. 94 87 return !inStrictContext 95 && static_cast<size_t>(evalSource.length()) < Options::maximumEvalCacheableSourceLength()88 && evalSource.length() < Options::maximumEvalCacheableSourceLength() 96 89 && isCacheableScope(scope); 97 90 } 98 91 static const int maxCacheEntries = 64; 99 92 100 typedef HashMap< SourceCodeKey, WriteBarrier<EvalExecutable>, SourceCodeKeyHash, SourceCodeKeyHashTraits> EvalCacheMap;93 typedef HashMap<RefPtr<StringImpl>, WriteBarrier<EvalExecutable>> EvalCacheMap; 101 94 EvalCacheMap m_cacheMap; 102 95 };
Note:
See TracChangeset
for help on using the changeset viewer.