Changeset 76177 in webkit for trunk/Source/JavaScriptCore/parser/SourceProvider.h
- Timestamp:
- Jan 19, 2011, 4:13:03 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/parser/SourceProvider.h
r76129 r76177 31 31 32 32 #include "UString.h" 33 #include <wtf/HashMap.h> 34 #include <wtf/PassOwnPtr.h> 33 35 #include <wtf/RefCounted.h> 36 #include <wtf/UnusedParam.h> 34 37 #include <wtf/text/TextPosition.h> 38 35 39 36 40 namespace JSC { 37 41 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 38 58 class SourceProvider : public RefCounted<SourceProvider> { 39 59 public: 40 SourceProvider(const UString& url )60 SourceProvider(const UString& url, SourceProviderCache* cache = 0) 41 61 : m_url(url) 42 62 , m_validated(false) 63 , m_cache(cache ? cache : new SourceProviderCache) 64 , m_cacheOwned(!cache) 43 65 { 44 66 } 45 virtual ~SourceProvider() { } 67 virtual ~SourceProvider() 68 { 69 if (m_cacheOwned) 70 delete m_cache; 71 } 46 72 47 73 virtual UString getRange(int start, int end) const = 0; … … 56 82 void setValid() { m_validated = true; } 57 83 84 SourceProviderCache* cache() const { return m_cache; } 85 void notifyCacheSizeChanged(int delta) { if (!m_cacheOwned) cacheSizeChanged(delta); } 86 58 87 private: 88 virtual void cacheSizeChanged(int delta) { UNUSED_PARAM(delta); } 89 59 90 UString m_url; 60 91 bool m_validated; 92 SourceProviderCache* m_cache; 93 bool m_cacheOwned; 61 94 }; 62 95
Note:
See TracChangeset
for help on using the changeset viewer.