Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(777)

Side by Side Diff: third_party/WebKit/Source/bindings/core/v8/V8ValueCache.h

Issue 2227933002: Revert CompressibleString (and its UMA) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address on Ilya's review Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2009 Google Inc. All rights reserved. 2 * Copyright (C) 2009 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 10 matching lines...) Expand all
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE. 23 * THE POSSIBILITY OF SUCH DAMAGE.
24 */ 24 */
25 25
26 #ifndef V8ValueCache_h 26 #ifndef V8ValueCache_h
27 #define V8ValueCache_h 27 #define V8ValueCache_h
28 28
29 #include "bindings/core/v8/V8GlobalValueMap.h" 29 #include "bindings/core/v8/V8GlobalValueMap.h"
30 #include "core/CoreExport.h" 30 #include "core/CoreExport.h"
31 #include "platform/text/CompressibleString.h"
32 #include "wtf/Allocator.h" 31 #include "wtf/Allocator.h"
33 #include "wtf/HashMap.h" 32 #include "wtf/HashMap.h"
34 #include "wtf/Noncopyable.h" 33 #include "wtf/Noncopyable.h"
35 #include "wtf/RefPtr.h" 34 #include "wtf/RefPtr.h"
36 #include "wtf/text/AtomicString.h" 35 #include "wtf/text/AtomicString.h"
37 #include "wtf/text/WTFString.h" 36 #include "wtf/text/WTFString.h"
38 #include <v8.h> 37 #include <v8.h>
39 38
40 namespace blink { 39 namespace blink {
41 40
(...skipping 16 matching lines...) Expand all
58 { 57 {
59 return data.GetParameter(); 58 return data.GetParameter();
60 } 59 }
61 60
62 static void OnWeakCallback(const v8::WeakCallbackInfo<WeakCallbackDataType>& ); 61 static void OnWeakCallback(const v8::WeakCallbackInfo<WeakCallbackDataType>& );
63 62
64 static void Dispose(v8::Isolate*, v8::Global<v8::String> value, StringImpl* key); 63 static void Dispose(v8::Isolate*, v8::Global<v8::String> value, StringImpl* key);
65 static void DisposeWeak(const v8::WeakCallbackInfo<WeakCallbackDataType>&); 64 static void DisposeWeak(const v8::WeakCallbackInfo<WeakCallbackDataType>&);
66 }; 65 };
67 66
68 class CompressibleStringCacheMapTraits : public V8GlobalValueMapTraits<Compressi bleStringImpl*, v8::String, v8::kWeakWithParameter> {
69 STATIC_ONLY(CompressibleStringCacheMapTraits);
70 public:
71 // Weak traits:
72 typedef CompressibleStringImpl WeakCallbackDataType;
73 typedef v8::GlobalValueMap<CompressibleStringImpl*, v8::String, Compressible StringCacheMapTraits> MapType;
74
75 static WeakCallbackDataType* WeakCallbackParameter(
76 MapType* map, CompressibleStringImpl* key, v8::Local<v8::String>& value) { return key; }
77 static void DisposeCallbackData(WeakCallbackDataType* callbackData) { }
78
79 static MapType* MapFromWeakCallbackInfo(
80 const v8::WeakCallbackInfo<WeakCallbackDataType>&);
81
82 static CompressibleStringImpl* KeyFromWeakCallbackInfo(
83 const v8::WeakCallbackInfo<WeakCallbackDataType>& data)
84 {
85 return data.GetParameter();
86 }
87
88 static void OnWeakCallback(const v8::WeakCallbackInfo<WeakCallbackDataType>& );
89
90 static void Dispose(v8::Isolate*, v8::Global<v8::String> value, Compressible StringImpl* key);
91 static void DisposeWeak(const v8::WeakCallbackInfo<WeakCallbackDataType>&);
92 };
93 67
94 class CORE_EXPORT StringCache { 68 class CORE_EXPORT StringCache {
95 USING_FAST_MALLOC(StringCache); 69 USING_FAST_MALLOC(StringCache);
96 WTF_MAKE_NONCOPYABLE(StringCache); 70 WTF_MAKE_NONCOPYABLE(StringCache);
97 public: 71 public:
98 explicit StringCache(v8::Isolate* isolate) 72 explicit StringCache(v8::Isolate* isolate) : m_stringCache(isolate) { }
99 : m_stringCache(isolate)
100 , m_compressibleStringCache(isolate)
101 {
102 }
103 73
104 v8::Local<v8::String> v8ExternalString(v8::Isolate* isolate, StringImpl* str ingImpl) 74 v8::Local<v8::String> v8ExternalString(v8::Isolate* isolate, StringImpl* str ingImpl)
105 { 75 {
106 ASSERT(stringImpl); 76 ASSERT(stringImpl);
107 if (m_lastStringImpl.get() == stringImpl) 77 if (m_lastStringImpl.get() == stringImpl)
108 return m_lastV8String.NewLocal(isolate); 78 return m_lastV8String.NewLocal(isolate);
109 return v8ExternalStringSlow(isolate, stringImpl); 79 return v8ExternalStringSlow(isolate, stringImpl);
110 } 80 }
111 81
112 v8::Local<v8::String> v8ExternalString(v8::Isolate* isolate, const Compressi bleString& string)
113 {
114 // Note that the last CompressibleString is not cached.
115 ASSERT(!string.isNull());
116 return v8ExternalStringSlow(isolate, string);
117 }
118
119 void setReturnValueFromString(v8::ReturnValue<v8::Value> returnValue, String Impl* stringImpl) 82 void setReturnValueFromString(v8::ReturnValue<v8::Value> returnValue, String Impl* stringImpl)
120 { 83 {
121 ASSERT(stringImpl); 84 ASSERT(stringImpl);
122 if (m_lastStringImpl.get() == stringImpl) 85 if (m_lastStringImpl.get() == stringImpl)
123 m_lastV8String.SetReturnValue(returnValue); 86 m_lastV8String.SetReturnValue(returnValue);
124 else 87 else
125 setReturnValueFromStringSlow(returnValue, stringImpl); 88 setReturnValueFromStringSlow(returnValue, stringImpl);
126 } 89 }
127 90
128 void dispose(); 91 void dispose();
129 92
130 friend class StringCacheMapTraits; 93 friend class StringCacheMapTraits;
131 friend class CompressibleStringCacheMapTraits;
132 94
133 private: 95 private:
134 v8::Local<v8::String> v8ExternalStringSlow(v8::Isolate*, StringImpl*); 96 v8::Local<v8::String> v8ExternalStringSlow(v8::Isolate*, StringImpl*);
135 v8::Local<v8::String> v8ExternalStringSlow(v8::Isolate*, const CompressibleS tring&);
136 void setReturnValueFromStringSlow(v8::ReturnValue<v8::Value>, StringImpl*); 97 void setReturnValueFromStringSlow(v8::ReturnValue<v8::Value>, StringImpl*);
137 v8::Local<v8::String> createStringAndInsertIntoCache(v8::Isolate*, StringImp l*); 98 v8::Local<v8::String> createStringAndInsertIntoCache(v8::Isolate*, StringImp l*);
138 v8::Local<v8::String> createStringAndInsertIntoCache(v8::Isolate*, const Com pressibleString&);
139 void InvalidateLastString(); 99 void InvalidateLastString();
140 100
141 StringCacheMapTraits::MapType m_stringCache; 101 StringCacheMapTraits::MapType m_stringCache;
142 StringCacheMapTraits::MapType::PersistentValueReference m_lastV8String; 102 StringCacheMapTraits::MapType::PersistentValueReference m_lastV8String;
143 103
144 CompressibleStringCacheMapTraits::MapType m_compressibleStringCache;
145
146 // Note: RefPtr is a must as we cache by StringImpl* equality, not identity 104 // Note: RefPtr is a must as we cache by StringImpl* equality, not identity
147 // hence lastStringImpl might be not a key of the cache (in sense of identit y) 105 // hence lastStringImpl might be not a key of the cache (in sense of identit y)
148 // and hence it's not refed on addition. 106 // and hence it's not refed on addition.
149 RefPtr<StringImpl> m_lastStringImpl; 107 RefPtr<StringImpl> m_lastStringImpl;
150 }; 108 };
151 109
152 } // namespace blink 110 } // namespace blink
153 111
154 #endif // V8ValueCache_h 112 #endif // V8ValueCache_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698