Ignore:
Timestamp:
Jan 19, 2011, 4:13:03 PM (14 years ago)
Author:
Antti Koivisto
Message:

Cache function offsets to speed up javascript parsing
https://bugs.webkit.org/show_bug.cgi?id=52622

Reviewed by Oliver Hunt.

Use cache to save function offsets and some other info.
This avoids quite a bit of work when reparsing the source.

Source/JavaScriptCore:

  • parser/ASTBuilder.h:
  • parser/JSParser.cpp:

(JSC::JSParser::CachedFunctionInfo::CachedFunctionInfo):
(JSC::JSParser::CachedFunctionInfo::approximateByteSize):
(JSC::JSParser::CachedFunctionInfo::closeBraceToken):
(JSC::JSParser::Scope::copyCapturedVariablesToVector):
(JSC::JSParser::Scope::saveFunctionInfo):
(JSC::JSParser::Scope::restoreFunctionInfo):
(JSC::JSParser::findCachedFunctionInfo):
(JSC::JSParser::JSParser):
(JSC::JSParser::parseProgram):
(JSC::JSParser::parseFunctionInfo):

  • parser/Lexer.h:

(JSC::Lexer::setOffset):
(JSC::Lexer::setLineNumber):
(JSC::Lexer::sourceProvider):

  • parser/SourceProvider.h:

(JSC::SourceProviderCache::SourceProviderCache):
(JSC::SourceProviderCache::~SourceProviderCache):
(JSC::SourceProviderCache::byteSize):
(JSC::SourceProviderCache::add):
(JSC::SourceProviderCache::get):
(JSC::SourceProvider::SourceProvider):
(JSC::SourceProvider::~SourceProvider):
(JSC::SourceProvider::cache):
(JSC::SourceProvider::notifyCacheSizeChanged):
(JSC::SourceProvider::cacheSizeChanged):

  • parser/SyntaxChecker.h:

Source/WebCore:

  • bindings/js/CachedScriptSourceProvider.h:

(WebCore::CachedScriptSourceProvider::cache):
(WebCore::CachedScriptSourceProvider::cacheSizeChanged):
(WebCore::CachedScriptSourceProvider::CachedScriptSourceProvider):

  • bindings/js/ScriptSourceProvider.h:

(WebCore::ScriptSourceProvider::ScriptSourceProvider):

  • loader/cache/CachedScript.cpp:

(WebCore::CachedScript::destroyDecodedData):
(WebCore::CachedScript::sourceProviderCache):
(WebCore::CachedScript::sourceProviderCacheSizeChanged):

  • loader/cache/CachedScript.h:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/parser/SourceProvider.h

    r76129 r76177  
    3131
    3232#include "UString.h"
     33#include <wtf/HashMap.h>
     34#include <wtf/PassOwnPtr.h>
    3335#include <wtf/RefCounted.h>
     36#include <wtf/UnusedParam.h>
    3437#include <wtf/text/TextPosition.h>
     38
    3539
    3640namespace JSC {
    3741
     42    class SourceProviderCache {
     43    public:
     44        struct Item {};
     45
     46        SourceProviderCache() : m_contentByteSize(0) {}
     47        ~SourceProviderCache() { deleteAllValues(m_map); }
     48       
     49        unsigned byteSize() const { return m_contentByteSize + sizeof(*this) + m_map.capacity() * sizeof(Item*); }
     50        void add(int sourcePosition, PassOwnPtr<Item> item, unsigned size) { m_map.add(sourcePosition, item.leakPtr()); m_contentByteSize += size; }
     51        const Item* get(int sourcePosition) const { return m_map.get(sourcePosition); }
     52
     53    private:
     54        HashMap<int, Item*> m_map;
     55        unsigned m_contentByteSize;
     56    };
     57
    3858    class SourceProvider : public RefCounted<SourceProvider> {
    3959    public:
    40         SourceProvider(const UString& url)
     60        SourceProvider(const UString& url, SourceProviderCache* cache = 0)
    4161            : m_url(url)
    4262            , m_validated(false)
     63            , m_cache(cache ? cache : new SourceProviderCache)
     64            , m_cacheOwned(!cache)
    4365        {
    4466        }
    45         virtual ~SourceProvider() { }
     67        virtual ~SourceProvider()
     68        {
     69            if (m_cacheOwned)
     70                delete m_cache;
     71        }
    4672
    4773        virtual UString getRange(int start, int end) const = 0;
     
    5682        void setValid() { m_validated = true; }
    5783
     84        SourceProviderCache* cache() const { return m_cache; }
     85        void notifyCacheSizeChanged(int delta) { if (!m_cacheOwned) cacheSizeChanged(delta); }
     86       
    5887    private:
     88        virtual void cacheSizeChanged(int delta) { UNUSED_PARAM(delta); }
     89
    5990        UString m_url;
    6091        bool m_validated;
     92        SourceProviderCache* m_cache;
     93        bool m_cacheOwned;
    6194    };
    6295
Note: See TracChangeset for help on using the changeset viewer.