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

Side by Side Diff: sky/engine/tonic/dart_string_cache.cc

Issue 924593002: Merge the tonic layer from skydart branch back to master (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: fix Created 5 years, 10 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
« no previous file with comments | « sky/engine/tonic/dart_string_cache.h ('k') | sky/engine/tonic/dart_value.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "sky/engine/config.h"
6 #include "sky/engine/tonic/dart_string_cache.h"
7
8 #include "sky/engine/tonic/dart_state.h"
9 #include "sky/engine/tonic/dart_string.h"
10
11 namespace blink {
12
13 DartStringCache::DartStringCache() : last_dart_string_(nullptr) {
14 }
15
16 DartStringCache::~DartStringCache() {
17 }
18
19 Dart_WeakPersistentHandle DartStringCache::GetSlow(StringImpl* string_impl,
20 bool auto_scope) {
21 if (Dart_WeakPersistentHandle string = cache_.get(string_impl)) {
22 last_dart_string_ = string;
23 last_string_impl_ = string_impl;
24 return string;
25 }
26
27 if (!auto_scope)
28 Dart_EnterScope();
29
30 Dart_Handle string = CreateDartString(string_impl);
31 DCHECK(!Dart_IsError(string));
32
33 intptr_t size_in_bytes = string_impl->sizeInBytes();
34 Dart_WeakPersistentHandle wrapper = Dart_NewWeakPersistentHandle(
35 string, string_impl, size_in_bytes, FinalizeCacheEntry);
36
37 string_impl->ref(); // Balanced in FinalizeCacheEntry.
38 cache_.set(string_impl, wrapper);
39
40 last_dart_string_ = wrapper;
41 last_string_impl_ = string_impl;
42
43 if (!auto_scope)
44 Dart_ExitScope();
45
46 return wrapper;
47 }
48
49 void DartStringCache::FinalizeCacheEntry(void* isolate_callback_data,
50 Dart_WeakPersistentHandle handle,
51 void* peer) {
52 DartState* state = reinterpret_cast<DartState*>(isolate_callback_data);
53 StringImpl* string_impl = reinterpret_cast<StringImpl*>(peer);
54 DartStringCache& cache = state->string_cache();
55
56 Dart_WeakPersistentHandle cached_handle = cache.cache_.take(string_impl);
57 ASSERT_UNUSED(cached_handle, handle == cached_handle);
58
59 if (cache.last_dart_string_ == handle) {
60 cache.last_dart_string_ = nullptr;
61 cache.last_string_impl_ = nullptr;
62 }
63
64 string_impl->deref();
65 }
66
67 } // namespace blink
OLDNEW
« no previous file with comments | « sky/engine/tonic/dart_string_cache.h ('k') | sky/engine/tonic/dart_value.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698