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

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

Issue 1389383003: WIP: Introduce CompressibleString Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 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 15 matching lines...) Expand all
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 "wtf/Allocator.h" 31 #include "wtf/Allocator.h"
32 #include "wtf/HashMap.h" 32 #include "wtf/HashMap.h"
33 #include "wtf/Noncopyable.h" 33 #include "wtf/Noncopyable.h"
34 #include "wtf/RefPtr.h" 34 #include "wtf/RefPtr.h"
35 #include "wtf/text/AtomicString.h" 35 #include "wtf/text/AtomicString.h"
36 #include "wtf/text/CompressableString.h"
36 #include "wtf/text/WTFString.h" 37 #include "wtf/text/WTFString.h"
37 #include <v8.h> 38 #include <v8.h>
38 39
39 namespace blink { 40 namespace blink {
40 41
41 class StringCacheMapTraits : public V8GlobalValueMapTraits<StringImpl*, v8::Stri ng, v8::kWeakWithParameter> { 42 class StringCacheMapTraits : public V8GlobalValueMapTraits<StringImpl*, v8::Stri ng, v8::kWeakWithParameter> {
42 STATIC_ONLY(StringCacheMapTraits); 43 STATIC_ONLY(StringCacheMapTraits);
43 public: 44 public:
44 // Weak traits: 45 // Weak traits:
45 typedef StringImpl WeakCallbackDataType; 46 typedef StringImpl WeakCallbackDataType;
(...skipping 26 matching lines...) Expand all
72 explicit StringCache(v8::Isolate* isolate) : m_stringCache(isolate) { } 73 explicit StringCache(v8::Isolate* isolate) : m_stringCache(isolate) { }
73 74
74 v8::Local<v8::String> v8ExternalString(v8::Isolate* isolate, StringImpl* str ingImpl) 75 v8::Local<v8::String> v8ExternalString(v8::Isolate* isolate, StringImpl* str ingImpl)
75 { 76 {
76 ASSERT(stringImpl); 77 ASSERT(stringImpl);
77 if (m_lastStringImpl.get() == stringImpl) 78 if (m_lastStringImpl.get() == stringImpl)
78 return m_lastV8String.NewLocal(isolate); 79 return m_lastV8String.NewLocal(isolate);
79 return v8ExternalStringSlow(isolate, stringImpl); 80 return v8ExternalStringSlow(isolate, stringImpl);
80 } 81 }
81 82
83 v8::Local<v8::String> v8ExternalString(v8::Isolate* isolate, PassRefPtr<Comp ressableString> string)
84 {
85 ASSERT(string);
86 return v8ExternalStringSlow(isolate, string);
87 }
88
82 void setReturnValueFromString(v8::ReturnValue<v8::Value> returnValue, String Impl* stringImpl) 89 void setReturnValueFromString(v8::ReturnValue<v8::Value> returnValue, String Impl* stringImpl)
83 { 90 {
84 ASSERT(stringImpl); 91 ASSERT(stringImpl);
85 if (m_lastStringImpl.get() == stringImpl) 92 if (m_lastStringImpl.get() == stringImpl)
86 m_lastV8String.SetReturnValue(returnValue); 93 m_lastV8String.SetReturnValue(returnValue);
87 else 94 else
88 setReturnValueFromStringSlow(returnValue, stringImpl); 95 setReturnValueFromStringSlow(returnValue, stringImpl);
89 } 96 }
90 97
91 void dispose(); 98 void dispose();
92 99
93 friend class StringCacheMapTraits; 100 friend class StringCacheMapTraits;
94 101
95 private: 102 private:
96 v8::Local<v8::String> v8ExternalStringSlow(v8::Isolate*, StringImpl*); 103 v8::Local<v8::String> v8ExternalStringSlow(v8::Isolate*, StringImpl*);
104 v8::Local<v8::String> v8ExternalStringSlow(v8::Isolate*, PassRefPtr<Compress ableString>);
97 void setReturnValueFromStringSlow(v8::ReturnValue<v8::Value>, StringImpl*); 105 void setReturnValueFromStringSlow(v8::ReturnValue<v8::Value>, StringImpl*);
98 v8::Local<v8::String> createStringAndInsertIntoCache(v8::Isolate*, StringImp l*); 106 v8::Local<v8::String> createStringAndInsertIntoCache(v8::Isolate*, StringImp l*);
107 v8::Local<v8::String> createStringAndInsertIntoCache(v8::Isolate*, PassRefPt r<CompressableString>);
99 void InvalidateLastString(); 108 void InvalidateLastString();
100 109
101 StringCacheMapTraits::MapType m_stringCache; 110 StringCacheMapTraits::MapType m_stringCache;
102 StringCacheMapTraits::MapType::PersistentValueReference m_lastV8String; 111 StringCacheMapTraits::MapType::PersistentValueReference m_lastV8String;
103 112
104 // Note: RefPtr is a must as we cache by StringImpl* equality, not identity 113 // Note: RefPtr is a must as we cache by StringImpl* equality, not identity
105 // hence lastStringImpl might be not a key of the cache (in sense of identit y) 114 // hence lastStringImpl might be not a key of the cache (in sense of identit y)
106 // and hence it's not refed on addition. 115 // and hence it's not refed on addition.
107 RefPtr<StringImpl> m_lastStringImpl; 116 RefPtr<StringImpl> m_lastStringImpl;
108 }; 117 };
109 118
110 } // namespace blink 119 } // namespace blink
111 120
112 #endif // V8ValueCache_h 121 #endif // V8ValueCache_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698