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

Unified Diff: tonic/dart_string_cache.cc

Issue 1244493002: Wholesale move sky/engine/tonic to tonic (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tonic/dart_string_cache.h ('k') | tonic/dart_timer_heap.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tonic/dart_string_cache.cc
diff --git a/tonic/dart_string_cache.cc b/tonic/dart_string_cache.cc
new file mode 100644
index 0000000000000000000000000000000000000000..3cb267b4e3683a14533ed82d597f58daa3150f45
--- /dev/null
+++ b/tonic/dart_string_cache.cc
@@ -0,0 +1,66 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "tonic/dart_string_cache.h"
+
+#include "tonic/dart_state.h"
+#include "tonic/dart_string.h"
+
+namespace blink {
+
+DartStringCache::DartStringCache() : last_dart_string_(nullptr) {
+}
+
+DartStringCache::~DartStringCache() {
+}
+
+Dart_WeakPersistentHandle DartStringCache::GetSlow(StringImpl* string_impl,
+ bool auto_scope) {
+ if (Dart_WeakPersistentHandle string = cache_.get(string_impl)) {
+ last_dart_string_ = string;
+ last_string_impl_ = string_impl;
+ return string;
+ }
+
+ if (!auto_scope)
+ Dart_EnterScope();
+
+ Dart_Handle string = CreateDartString(string_impl);
+ DCHECK(!Dart_IsError(string));
+
+ intptr_t size_in_bytes = string_impl->sizeInBytes();
+ Dart_WeakPersistentHandle wrapper = Dart_NewWeakPersistentHandle(
+ string, string_impl, size_in_bytes, FinalizeCacheEntry);
+
+ string_impl->ref(); // Balanced in FinalizeCacheEntry.
+ cache_.set(string_impl, wrapper);
+
+ last_dart_string_ = wrapper;
+ last_string_impl_ = string_impl;
+
+ if (!auto_scope)
+ Dart_ExitScope();
+
+ return wrapper;
+}
+
+void DartStringCache::FinalizeCacheEntry(void* isolate_callback_data,
+ Dart_WeakPersistentHandle handle,
+ void* peer) {
+ DartState* state = reinterpret_cast<DartState*>(isolate_callback_data);
+ StringImpl* string_impl = reinterpret_cast<StringImpl*>(peer);
+ DartStringCache& cache = state->string_cache();
+
+ Dart_WeakPersistentHandle cached_handle = cache.cache_.take(string_impl);
+ ASSERT_UNUSED(cached_handle, handle == cached_handle);
+
+ if (cache.last_dart_string_ == handle) {
+ cache.last_dart_string_ = nullptr;
+ cache.last_string_impl_ = nullptr;
+ }
+
+ string_impl->deref();
+}
+
+} // namespace blink
« no previous file with comments | « tonic/dart_string_cache.h ('k') | tonic/dart_timer_heap.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698