Index: Source/bindings/core/dart/DartStringCache.h |
diff --git a/Source/platform/graphics/GraphicsContextStateSaver.h b/Source/bindings/core/dart/DartStringCache.h |
similarity index 56% |
copy from Source/platform/graphics/GraphicsContextStateSaver.h |
copy to Source/bindings/core/dart/DartStringCache.h |
index 936d22a727de1dc15a3a4a21ece3730893f7c59a..3ab2b869931e4760d5a60e65d7d64cfd6a05a385 100644 |
--- a/Source/platform/graphics/GraphicsContextStateSaver.h |
+++ b/Source/bindings/core/dart/DartStringCache.h |
@@ -1,4 +1,5 @@ |
-// Copyright (C) 2013 Google Inc. All rights reserved. |
+// Copyright 2012, Google Inc. |
+// All rights reserved. |
// |
// Redistribution and use in source and binary forms, with or without |
// modification, are permitted provided that the following conditions are |
@@ -26,60 +27,49 @@ |
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
-#ifndef GraphicsContextStateSaver_h |
-#define GraphicsContextStateSaver_h |
+#ifndef DartStringCache_h |
+#define DartStringCache_h |
-#include "platform/PlatformExport.h" |
-#include "platform/graphics/GraphicsContext.h" |
+#include "wtf/HashMap.h" |
+#include "wtf/RefPtr.h" |
+#include "wtf/text/StringHash.h" |
+#include "wtf/text/StringImpl.h" |
+ |
+#include <dart_api.h> |
namespace blink { |
-class PLATFORM_EXPORT GraphicsContextStateSaver { |
- WTF_MAKE_FAST_ALLOCATED(GraphicsContextStateSaver); |
+class DartStringCache { |
public: |
- GraphicsContextStateSaver(GraphicsContext& context, bool saveAndRestore = true) |
- : m_context(context) |
- , m_saveAndRestore(saveAndRestore) |
- { |
- if (m_saveAndRestore) |
- m_context.save(); |
- } |
+ DartStringCache(); |
- ~GraphicsContextStateSaver() |
+ Dart_WeakPersistentHandle get(StringImpl* stringImpl, bool autoDartScope = true) |
{ |
- if (m_saveAndRestore) |
- m_context.restore(); |
- } |
+ ASSERT(stringImpl); |
- void save() |
- { |
- ASSERT(!m_saveAndRestore); |
- m_context.save(); |
- m_saveAndRestore = true; |
- } |
+ if (m_lastStringImpl.get() == stringImpl) |
+ return m_lastDartString; |
- void saveIfNeeded() |
- { |
- if (saved()) |
- return; |
- save(); |
+ return getSlow(stringImpl, autoDartScope); |
} |
- void restore() |
- { |
- ASSERT(m_saveAndRestore); |
- m_context.restore(); |
- m_saveAndRestore = false; |
- } |
+ void clearWeakHandles(); |
- GraphicsContext* context() const { return &m_context; } |
- bool saved() const { return m_saveAndRestore; } |
+ // FIXME: implement clearing on GC. |
private: |
- GraphicsContext& m_context; |
- bool m_saveAndRestore; |
+ Dart_WeakPersistentHandle getSlow(StringImpl*, bool autoDartScope); |
+ static void handleFinalizer(void*, Dart_WeakPersistentHandle, void* peer); |
+ |
+ typedef HashMap<StringImpl*, Dart_WeakPersistentHandle> StringCache; |
+ StringCache m_stringCache; |
+ Dart_WeakPersistentHandle m_lastDartString; |
+ // Note: RefPtr is a must as we cache by StringImpl* equality, not identity |
+ // hence lastStringImpl might be not a key of the cache (in sense of identity) |
+ // and hence it's not refed on addition. |
+ RefPtr<StringImpl> m_lastStringImpl; |
}; |
-} // namespace blink |
+} |
-#endif // GraphicsContextStateSaver_h |
+#endif |