OLD | NEW |
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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 static void Dispose(v8::Isolate*, v8::UniquePersistent<v8::String> value, St
ringImpl* key); | 59 static void Dispose(v8::Isolate*, v8::UniquePersistent<v8::String> value, St
ringImpl* key); |
60 }; | 60 }; |
61 | 61 |
62 | 62 |
63 class CORE_EXPORT StringCache { | 63 class CORE_EXPORT StringCache { |
64 WTF_MAKE_NONCOPYABLE(StringCache); | 64 WTF_MAKE_NONCOPYABLE(StringCache); |
65 public: | 65 public: |
66 StringCache(v8::Isolate* isolate) : m_stringCache(isolate) { } | 66 StringCache(v8::Isolate* isolate) : m_stringCache(isolate) { } |
67 ~StringCache(); | 67 ~StringCache(); |
68 | 68 |
69 v8::Handle<v8::String> v8ExternalString(StringImpl* stringImpl, v8::Isolate*
isolate) | 69 v8::Local<v8::String> v8ExternalString(StringImpl* stringImpl, v8::Isolate*
isolate) |
70 { | 70 { |
71 ASSERT(stringImpl); | 71 ASSERT(stringImpl); |
72 if (m_lastStringImpl.get() == stringImpl) | 72 if (m_lastStringImpl.get() == stringImpl) |
73 return m_lastV8String.NewLocal(isolate); | 73 return m_lastV8String.NewLocal(isolate); |
74 return v8ExternalStringSlow(isolate, stringImpl); | 74 return v8ExternalStringSlow(isolate, stringImpl); |
75 } | 75 } |
76 | 76 |
77 void setReturnValueFromString(v8::ReturnValue<v8::Value> returnValue, String
Impl* stringImpl) | 77 void setReturnValueFromString(v8::ReturnValue<v8::Value> returnValue, String
Impl* stringImpl) |
78 { | 78 { |
79 ASSERT(stringImpl); | 79 ASSERT(stringImpl); |
80 if (m_lastStringImpl.get() == stringImpl) | 80 if (m_lastStringImpl.get() == stringImpl) |
81 m_lastV8String.SetReturnValue(returnValue); | 81 m_lastV8String.SetReturnValue(returnValue); |
82 else | 82 else |
83 setReturnValueFromStringSlow(returnValue, stringImpl); | 83 setReturnValueFromStringSlow(returnValue, stringImpl); |
84 } | 84 } |
85 | 85 |
86 friend class StringCacheMapTraits; | 86 friend class StringCacheMapTraits; |
87 | 87 |
88 private: | 88 private: |
89 v8::Handle<v8::String> v8ExternalStringSlow(v8::Isolate*, StringImpl*); | 89 v8::Local<v8::String> v8ExternalStringSlow(v8::Isolate*, StringImpl*); |
90 void setReturnValueFromStringSlow(v8::ReturnValue<v8::Value>, StringImpl*); | 90 void setReturnValueFromStringSlow(v8::ReturnValue<v8::Value>, StringImpl*); |
91 v8::Local<v8::String> createStringAndInsertIntoCache(v8::Isolate*, StringImp
l*); | 91 v8::Local<v8::String> createStringAndInsertIntoCache(v8::Isolate*, StringImp
l*); |
92 void InvalidateLastString(); | 92 void InvalidateLastString(); |
93 | 93 |
94 StringCacheMapTraits::MapType m_stringCache; | 94 StringCacheMapTraits::MapType m_stringCache; |
95 StringCacheMapTraits::MapType::PersistentValueReference m_lastV8String; | 95 StringCacheMapTraits::MapType::PersistentValueReference m_lastV8String; |
96 | 96 |
97 // Note: RefPtr is a must as we cache by StringImpl* equality, not identity | 97 // Note: RefPtr is a must as we cache by StringImpl* equality, not identity |
98 // hence lastStringImpl might be not a key of the cache (in sense of identit
y) | 98 // hence lastStringImpl might be not a key of the cache (in sense of identit
y) |
99 // and hence it's not refed on addition. | 99 // and hence it's not refed on addition. |
100 RefPtr<StringImpl> m_lastStringImpl; | 100 RefPtr<StringImpl> m_lastStringImpl; |
101 }; | 101 }; |
102 | 102 |
103 } // namespace blink | 103 } // namespace blink |
104 | 104 |
105 #endif // V8ValueCache_h | 105 #endif // V8ValueCache_h |
OLD | NEW |