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